pub struct PendingDeviceCode { /* private fields */ }Expand description
A device code flow that is waiting for the user to authorize.
Returned by DeviceCodeStrategy::begin. Display the
user_code and
verification_uri_complete to the user
(or call open_in_browser), then call
poll_for_token to wait for authorization.
§Example
let pending = strategy.begin().await?;
println!("Go to: {}", pending.verification_uri_complete());
println!("Enter code: {}", pending.user_code());
let token = pending.poll_for_token().await?;Implementations§
Source§impl PendingDeviceCode
impl PendingDeviceCode
Sourcepub fn verification_uri(&self) -> &str
pub fn verification_uri(&self) -> &str
The base verification URI (without the user code embedded).
Sourcepub fn verification_uri_complete(&self) -> &str
pub fn verification_uri_complete(&self) -> &str
The full verification URI with the user code pre-filled.
Sourcepub fn expires_in(&self) -> u64
pub fn expires_in(&self) -> u64
How many seconds the device code remains valid.
Sourcepub fn open_in_browser(&self) -> bool
pub fn open_in_browser(&self) -> bool
Open the verification URI in the user’s default browser.
Returns true if the browser was opened successfully.
Sourcepub async fn poll_for_token(self) -> Result<Token, AuthError>
pub async fn poll_for_token(self) -> Result<Token, AuthError>
Poll the auth server until the user authorizes (or the code expires).
This method consumes self and blocks asynchronously, polling at a
server-controlled interval (starting at 5 seconds). It returns a
Token on success.
§Errors
AuthError::AccessDenied— the user rejected the request.AuthError::TokenExpired— the device code expired before the user authorized.AuthError::Request— a network error occurred while polling.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PendingDeviceCode
impl RefUnwindSafe for PendingDeviceCode
impl Send for PendingDeviceCode
impl Sync for PendingDeviceCode
impl Unpin for PendingDeviceCode
impl UnsafeUnpin for PendingDeviceCode
impl UnwindSafe for PendingDeviceCode
Blanket Implementations§
impl<T> AuthStrategyBounds for T
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
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>
Converts
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>
Converts
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