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.