Skip to main content

DeviceFlow

Struct DeviceFlow 

Source
pub struct DeviceFlow<'a> { /* private fields */ }
Expand description

A GitHub OAuth device-flow client for one OAuth App.

Implementations§

Source§

impl<'a> DeviceFlow<'a>

Source

pub fn new(http: &'a dyn HttpClient, client_id: &'a str) -> Self

Create a flow for the OAuth App client_id, sending requests through http and requesting DEFAULT_SCOPE.

Source

pub fn with_scope(self, scope: &'a str) -> Self

Request scope (space-separated OAuth scopes) instead of DEFAULT_SCOPE.

Source

pub fn request_device_code( &self, ) -> Result<DeviceAuthorization, DeviceFlowError>

Step 1: ask GitHub for a device code and the user code to display.

Missing interval / expires_in fall back to 5 seconds / 15 minutes, and a missing verification_uri to VERIFICATION_URL.

§Errors

DeviceFlowError::Http when the request fails, DeviceFlowError::DeviceCodeRejected when GitHub returns an OAuth error, and DeviceFlowError::MissingField when device_code or user_code is absent.

Source

pub fn poll( &self, device: &DeviceAuthorization, current_interval: Duration, ) -> Result<PollStatus, DeviceFlowError>

Poll the token endpoint once for device.

current_interval is the wait in effect; it is the base for the RFC 8628 back-off when GitHub answers slow_down without a new interval.

§Errors

DeviceFlowError::Http when the request fails, DeviceFlowError::Expired / DeviceFlowError::AccessDenied for the terminal OAuth errors, DeviceFlowError::TokenRejected for other OAuth errors, and DeviceFlowError::UnexpectedResponse when the response carries neither a token nor an error.

Source

pub fn wait_for_token( &self, device: &DeviceAuthorization, clock: &mut dyn PollClock, ) -> Result<String, DeviceFlowError>

Step 2: poll until the user authorizes and return the access token.

Waits at least device.interval (never less than one second) before every poll, adopts the longer interval on slow_down, and gives up once device.expires_in has elapsed since the call started.

§Errors

DeviceFlowError::TimedOut when the codes expire locally, plus every error poll returns.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for DeviceFlow<'a>

§

impl<'a> !UnwindSafe for DeviceFlow<'a>

§

impl<'a> Freeze for DeviceFlow<'a>

§

impl<'a> Send for DeviceFlow<'a>

§

impl<'a> Sync for DeviceFlow<'a>

§

impl<'a> Unpin for DeviceFlow<'a>

§

impl<'a> UnsafeUnpin for DeviceFlow<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.