Skip to main content

JwtGenerator

Trait JwtGenerator 

Source
pub trait JwtGenerator: Send + Sync {
    // Required methods
    fn generate_jwt<'life0, 'async_trait>(
        &'life0 self,
        app_id: GitHubAppId,
    ) -> Pin<Box<dyn Future<Output = Result<JsonWebToken, AuthError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn expiration_duration(&self) -> Duration;
}
Expand description

Interface for JWT token generation and signing.

This trait abstracts JWT generation to allow for different implementations (production RSA signing, mock generators for testing, etc.).

§Examples

let app_id = GitHubAppId::new(123456);
let token = generator.generate_jwt(app_id).await.unwrap();
assert!(!token.is_expired());

Required Methods§

Source

fn generate_jwt<'life0, 'async_trait>( &'life0 self, app_id: GitHubAppId, ) -> Pin<Box<dyn Future<Output = Result<JsonWebToken, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate a JWT token for GitHub App authentication.

Creates a JWT with the following claims:

  • iss: GitHub App ID
  • iat: Current timestamp (issued at)
  • exp: Expiration timestamp (issued at + duration, max 10 minutes)
§Arguments
  • app_id - The GitHub App ID to include in the token
§Returns

A JsonWebToken containing the signed JWT string and metadata.

§Errors

Returns AuthError if:

  • Private key is invalid or cannot be loaded
  • JWT signing fails
  • System clock is unreliable
§Examples
let app_id = GitHubAppId::new(123456);
let jwt = generator.generate_jwt(app_id).await.expect("JWT generation failed");

// Token is valid for up to 10 minutes
assert!(!jwt.is_expired());
assert_eq!(jwt.app_id(), app_id);
Source

fn expiration_duration(&self) -> Duration

Get the JWT expiration duration configured for this generator.

Returns the duration from issuance to expiration. This value should not exceed 10 minutes (GitHub’s maximum).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§