pub struct GoogleAuth { /* private fields */ }Expand description
OAuth2 client with PKCE support
Implementations§
Source§impl GoogleAuth
impl GoogleAuth
Sourcepub async fn request_device_code(
&self,
scopes: &[String],
) -> Result<DeviceAuthChallenge>
pub async fn request_device_code( &self, scopes: &[String], ) -> Result<DeviceAuthChallenge>
Start a device flow asking for exactly scopes — the caller’s
flag-derived set, already intersected with Google’s allowlist by
[device_flow_scopes]. Returns the challenge to display to the user.
Sourcepub async fn poll_device_code(
&self,
challenge: &mut DeviceAuthChallenge,
scopes: &[String],
) -> Result<Option<TokenStorage>>
pub async fn poll_device_code( &self, challenge: &mut DeviceAuthChallenge, scopes: &[String], ) -> Result<Option<TokenStorage>>
Poll once. Returns Ok(None) while the user has not approved yet
(caller sleeps retry_after() and retries), Ok(Some) with the
stored token on approval, or Err on denial/expiry/failure.
scopes is the same set Self::request_device_code was called with:
it is what the credential records when Google’s response omits scope,
so the fallback is what was requested, never the index superset.
Sourcepub async fn login(&self, scopes: &[String]) -> Result<TokenStorage>
pub async fn login(&self, scopes: &[String]) -> Result<TokenStorage>
Fresh interactive login: drops any stored (possibly dead) token, runs
the PKCE browser flow with exactly scopes, saves and returns the new
token. The caller decides the set — see super::login_scopes,
super::scopes_for_service and super::scopes.
Source§impl GoogleAuth
impl GoogleAuth
Sourcepub async fn new(config: OAuthConfig) -> Result<Self>
pub async fn new(config: OAuthConfig) -> Result<Self>
Create new GoogleAuth from config
Sourcepub async fn new_for(
config: OAuthConfig,
account: impl Into<String>,
) -> Result<Self>
pub async fn new_for( config: OAuthConfig, account: impl Into<String>, ) -> Result<Self>
Create an auth handle bound to one named account’s own token (multi-account support). Same OAuth client and scopes; every store read and write targets that account’s keyring entry / fallback file exclusively. The name is validated and normalized here (rejects spaces, colons, and path separators; lowercased).
Sourcepub async fn with_account_store(
&self,
account: impl Into<String>,
) -> Result<Self>
pub async fn with_account_store( &self, account: impl Into<String>, ) -> Result<Self>
A handle bound to account’s own token store, reusing this handle’s
config (and thus the same OAuth client). The token cache is NOT
shared: the new handle loads the named account’s stored token.
This is what commands/auth.rs uses to rebind a default handle when
a per-command --account is present.
Sourcepub async fn with_default_account_store(&self) -> Result<Self>
pub async fn with_default_account_store(&self) -> Result<Self>
A fresh handle on the DEFAULT account’s store — today’s exact entry naming, no account suffix.
grr auth login/status rebuild their handle through this so a
named --account and the default take the same code path; without
an account it is behavior-identical to the original construction.
Sourcepub fn token_backend(&self) -> &'static str
pub fn token_backend(&self) -> &'static str
Token storage backend in use (for logs and auth login output).
Sourcepub async fn granted_scopes(&self) -> Vec<String>
pub async fn granted_scopes(&self) -> Vec<String>
The scope set the credential in hand holds — what Google actually
granted, or the requested set when its response was silent — split out
of TokenStorage::scope. Empty before any credential is loaded in
this process (nothing is read from the keyring here), and for a token
record written before the field existed.
grr auth status reports this. Only the credential knows what it
holds: auth login’s count is what was requested, and the consent
screen lets a user approve a subset of that.
Sourcepub async fn get_access_token(&self) -> Result<String>
pub async fn get_access_token(&self) -> Result<String>
Get valid access token, refreshing if necessary
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for GoogleAuth
impl !UnwindSafe for GoogleAuth
impl Freeze for GoogleAuth
impl Send for GoogleAuth
impl Sync for GoogleAuth
impl Unpin for GoogleAuth
impl UnsafeUnpin for GoogleAuth
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);