pub struct InstallationToken { /* private fields */ }Expand description
Installation-scoped access token for GitHub API operations.
Installation tokens provide access to perform operations on behalf of a specific installation. They have a 1-hour lifetime and include permission and repository scope information.
The token string is never exposed in Debug output for security.
§Examples
use github_bot_sdk::auth::{InstallationToken, InstallationId, InstallationPermissions, Permission, RepositoryId};
use chrono::{Utc, Duration};
let installation_id = InstallationId::new(456);
let expires_at = Utc::now() + Duration::hours(1);
let permissions = InstallationPermissions::default();
let repositories = vec![RepositoryId::new(789)];
let token = InstallationToken::new(
"ghs_token".to_string(),
installation_id,
expires_at,
permissions,
repositories,
);
assert_eq!(token.installation_id(), installation_id);
assert!(!token.is_expired());Implementations§
Source§impl InstallationToken
impl InstallationToken
Sourcepub fn new(
token: String,
installation_id: InstallationId,
expires_at: DateTime<Utc>,
permissions: InstallationPermissions,
repositories: Vec<RepositoryId>,
) -> Self
pub fn new( token: String, installation_id: InstallationId, expires_at: DateTime<Utc>, permissions: InstallationPermissions, repositories: Vec<RepositoryId>, ) -> Self
Create a new installation token.
§Arguments
token- The token string from GitHub APIinstallation_id- The installation this token is forexpires_at- When the token expires (typically 1 hour)permissions- The permissions granted to this tokenrepositories- The repositories this token can access
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 installation_id(&self) -> InstallationId
pub fn installation_id(&self) -> InstallationId
Get the installation ID this token is for.
Sourcepub fn expires_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
Get when this token expires.
Sourcepub fn permissions(&self) -> &InstallationPermissions
pub fn permissions(&self) -> &InstallationPermissions
Get the permissions granted to this token.
Sourcepub fn repositories(&self) -> &[RepositoryId]
pub fn repositories(&self) -> &[RepositoryId]
Get the repositories this token can access.
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 has_permission(&self, permission: Permission) -> bool
pub fn has_permission(&self, permission: Permission) -> bool
Check if the token has a specific permission.
§Examples
let mut permissions = InstallationPermissions::default();
permissions.issues = PermissionLevel::Write;
let token = InstallationToken::new(
"token".to_string(),
InstallationId::new(1),
Utc::now() + Duration::hours(1),
permissions,
vec![],
);
assert!(token.has_permission(Permission::ReadIssues));
assert!(token.has_permission(Permission::WriteIssues));
assert!(!token.has_permission(Permission::WriteContents));Sourcepub fn can_access_repository(&self, repo_id: RepositoryId) -> bool
pub fn can_access_repository(&self, repo_id: RepositoryId) -> bool
Check if the token can access a specific repository.
Trait Implementations§
Source§impl Clone for InstallationToken
impl Clone for InstallationToken
Source§fn clone(&self) -> InstallationToken
fn clone(&self) -> InstallationToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more