Skip to main content

OAuthDeviceFlowProvider

Trait OAuthDeviceFlowProvider 

Source
pub trait OAuthDeviceFlowProvider: Send + Sync {
    // Required methods
    fn request_device_code(
        &self,
        client_id: &str,
        scopes: &str,
    ) -> impl Future<Output = Result<DeviceCodeResponse, PlatformError>> + Send;
    fn poll_for_token(
        &self,
        client_id: &str,
        device_code: &str,
        interval: Duration,
        expires_in: Duration,
    ) -> impl Future<Output = Result<String, PlatformError>> + Send;
    fn fetch_user_profile(
        &self,
        access_token: &str,
    ) -> impl Future<Output = Result<PlatformUserProfile, PlatformError>> + Send;
}
Expand description

Two-phase OAuth 2.0 device authorization flow (RFC 8628).

The CLI calls request_device_code, displays the user_code and verification_uri, optionally opens a browser, then calls poll_for_token. All presentation logic stays in the CLI.

Usage:

let resp = provider.request_device_code(CLIENT_ID, "read:user gist").await?;
// CLI: display resp.user_code, open resp.verification_uri
let token = provider.poll_for_token(CLIENT_ID, &resp.device_code, Duration::from_secs(resp.interval), expires_at).await?;
let profile = provider.fetch_user_profile(&token).await?;

Required Methods§

Source

fn request_device_code( &self, client_id: &str, scopes: &str, ) -> impl Future<Output = Result<DeviceCodeResponse, PlatformError>> + Send

Request a device code to begin the device authorization flow.

Args:

  • client_id: OAuth application client ID.
  • scopes: Space-separated OAuth scopes to request.
Source

fn poll_for_token( &self, client_id: &str, device_code: &str, interval: Duration, expires_in: Duration, ) -> impl Future<Output = Result<String, PlatformError>> + Send

Poll for the access token until granted, denied, or the lifetime elapses.

Args:

  • client_id: OAuth application client ID.
  • device_code: Device code from request_device_code.
  • interval: Minimum time between poll attempts.
  • expires_in: Total lifetime of the device code (stop polling after this elapses).
Source

fn fetch_user_profile( &self, access_token: &str, ) -> impl Future<Output = Result<PlatformUserProfile, PlatformError>> + Send

Fetch the authenticated user’s profile using the access token.

Args:

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§