pub struct JsonWebToken { /* private fields */ }Expand description
JWT token for GitHub App authentication.
JSON Web Tokens (JWTs) are used to authenticate as a GitHub App. They have a maximum lifetime of 10 minutes and are used to obtain installation tokens.
The token string is never exposed in Debug output for security.
§Examples
use github_bot_sdk::auth::{JsonWebToken, GitHubAppId};
use chrono::{Utc, Duration};
let app_id = GitHubAppId::new(123);
let expires_at = Utc::now() + Duration::minutes(10);
let jwt = JsonWebToken::new("encoded.jwt.token".to_string(), app_id, expires_at);
assert!(!jwt.is_expired());
assert_eq!(jwt.app_id(), app_id);Implementations§
Source§impl JsonWebToken
impl JsonWebToken
Sourcepub fn new(
token: String,
app_id: GitHubAppId,
expires_at: DateTime<Utc>,
) -> Self
pub fn new( token: String, app_id: GitHubAppId, expires_at: DateTime<Utc>, ) -> Self
Create a new JWT token.
§Arguments
token- The encoded JWT stringapp_id- The GitHub App ID this token representsexpires_at- When the token expires (max 10 minutes from creation)
Sourcepub fn token(&self) -> &str
pub fn token(&self) -> &str
Get the token string for use in API requests.
This should be included in the Authorization header as:
Authorization: Bearer <token>
Sourcepub fn app_id(&self) -> GitHubAppId
pub fn app_id(&self) -> GitHubAppId
Get the GitHub App ID this token represents.
Sourcepub fn expires_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
Get when this token expires.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if the token is currently expired.
Sourcepub fn expires_soon(&self, margin: Duration) -> bool
pub fn expires_soon(&self, margin: Duration) -> bool
Check if the token will expire soon.
§Arguments
margin- How far in the future to check (e.g., 5 minutes)
Returns true if the token will expire within the margin period.
Sourcepub fn time_until_expiry(&self) -> Duration
pub fn time_until_expiry(&self) -> Duration
Get the time remaining until expiry.
Trait Implementations§
Source§impl Clone for JsonWebToken
impl Clone for JsonWebToken
Source§fn clone(&self) -> JsonWebToken
fn clone(&self) -> JsonWebToken
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for JsonWebToken
impl RefUnwindSafe for JsonWebToken
impl Send for JsonWebToken
impl Sync for JsonWebToken
impl Unpin for JsonWebToken
impl UnsafeUnpin for JsonWebToken
impl UnwindSafe for JsonWebToken
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
Mutably borrows from an owned value. Read more