pub struct TokenResolver { /* private fields */ }Expand description
Centralized token resolver for GitHub authentication.
The resolver caches tokens and supports async resolution for modes that may require I/O (e.g., reading private key files).
§Default setup
let resolver = TokenResolver::default(); // uses gh auth token if no env var set
let token = resolver.get_token().await?;Implementations§
Source§impl TokenResolver
impl TokenResolver
Sourcepub fn new(mode: TokenMode) -> Self
pub fn new(mode: TokenMode) -> Self
Create a new TokenResolver with the specified mode.
allow_gh_fallback defaults to true — gh auth token is tried last if env vars
and config are not set.
Sourcepub fn from_config(
mode_str: Option<&str>,
app_id: Option<String>,
private_key_path: Option<String>,
allow_gh_fallback: bool,
) -> Self
pub fn from_config( mode_str: Option<&str>, app_id: Option<String>, private_key_path: Option<String>, allow_gh_fallback: bool, ) -> Self
Create a TokenResolver from configuration values.
Sourcepub fn default_env() -> Self
pub fn default_env() -> Self
Create a default TokenResolver using environment variables with gh CLI fallback.
Sourcepub fn with_gh_fallback(self, enabled: bool) -> Self
pub fn with_gh_fallback(self, enabled: bool) -> Self
Enable or disable gh auth token CLI fallback.
Defaults to true — disable only to enforce explicit token configuration.
Sourcepub async fn get_token(&self) -> Result<Option<String>>
pub async fn get_token(&self) -> Result<Option<String>>
Resolve the GitHub token asynchronously.
Returns Ok(Some(token)) if a token is available,
Ok(None) if no token could be resolved,
or Err if an error occurred during resolution.
Sourcepub fn get_token_sync(&self) -> Result<Option<String>>
pub fn get_token_sync(&self) -> Result<Option<String>>
Get token synchronously (for contexts where async is not available).
Works for Env mode (env vars, config, and gh CLI fallback). GitHub App mode requires async due to file reading.
Sourcepub async fn clear_cache(&self)
pub async fn clear_cache(&self)
Clear the cached token (useful when token is known to be invalid).
Trait Implementations§
Source§impl Clone for TokenResolver
impl Clone for TokenResolver
Source§impl Debug for TokenResolver
impl Debug for TokenResolver
Auto Trait Implementations§
impl !RefUnwindSafe for TokenResolver
impl !UnwindSafe for TokenResolver
impl Freeze for TokenResolver
impl Send for TokenResolver
impl Sync for TokenResolver
impl Unpin for TokenResolver
impl UnsafeUnpin for TokenResolver
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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