pub struct DeviceFlow<'a> { /* private fields */ }Expand description
A GitHub OAuth device-flow client for one OAuth App.
Implementations§
Source§impl<'a> DeviceFlow<'a>
impl<'a> DeviceFlow<'a>
Sourcepub fn new(http: &'a dyn HttpClient, client_id: &'a str) -> Self
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.
Sourcepub fn with_scope(self, scope: &'a str) -> Self
pub fn with_scope(self, scope: &'a str) -> Self
Request scope (space-separated OAuth scopes) instead of
DEFAULT_SCOPE.
Sourcepub fn request_device_code(
&self,
) -> Result<DeviceAuthorization, DeviceFlowError>
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.
Sourcepub fn poll(
&self,
device: &DeviceAuthorization,
current_interval: Duration,
) -> Result<PollStatus, DeviceFlowError>
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.
Sourcepub fn wait_for_token(
&self,
device: &DeviceAuthorization,
clock: &mut dyn PollClock,
) -> Result<String, DeviceFlowError>
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.