pub struct TokenGenerator { /* private fields */ }Expand description
A utility to generate auth tokens to be used in Objectstore requests.
Tokens are signed with an EdDSA private key and have certain permissions and expiry timeouts applied.
Use this for internal services that have access to an EdDSA keypair. You can pass a
TokenGenerator directly to ClientBuilder::token,
and it will be automatically converted into a TokenProvider::Generator.
Implementations§
Source§impl TokenGenerator
impl TokenGenerator
Sourcepub fn new(secret_key: SecretKey) -> Result<TokenGenerator>
pub fn new(secret_key: SecretKey) -> Result<TokenGenerator>
Create a new TokenGenerator for a given key configuration.
Sourcepub fn expiry_seconds(self, expiry_seconds: u64) -> Self
pub fn expiry_seconds(self, expiry_seconds: u64) -> Self
Set the expiry duration for tokens signed by this generator.
Sourcepub fn permissions(self, permissions: &[Permission]) -> Self
pub fn permissions(self, permissions: &[Permission]) -> Self
Set the permissions that will be granted to tokens signed by this generator.
Sourcepub fn sign(&self, scope: &Scope) -> Result<String>
pub fn sign(&self, scope: &Scope) -> Result<String>
Sign a token for the given Scope, returning the JWT string.
Use this to produce a static token that can be handed to an external service
which then passes it to ClientBuilder::token.
§Errors
Returns an error if the scope is invalid or the JWT cannot be signed.
Trait Implementations§
Source§impl Debug for TokenGenerator
impl Debug for TokenGenerator
Source§impl From<TokenGenerator> for TokenProvider
impl From<TokenGenerator> for TokenProvider
Source§fn from(generator: TokenGenerator) -> Self
fn from(generator: TokenGenerator) -> Self
Auto Trait Implementations§
impl Freeze for TokenGenerator
impl RefUnwindSafe for TokenGenerator
impl Send for TokenGenerator
impl Sync for TokenGenerator
impl Unpin for TokenGenerator
impl UnsafeUnpin for TokenGenerator
impl UnwindSafe for TokenGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more