oauth2_github/
device_authorization_grant.rs

1use oauth2_client::{
2    re_exports::{ClientId, ClientSecret, Url, UrlParseError},
3    Provider, ProviderExtDeviceAuthorizationGrant,
4};
5
6use crate::{GithubScope, DEVICE_AUTHORIZATION_URL, TOKEN_URL};
7
8#[derive(Debug, Clone)]
9pub struct GithubProviderWithDevice {
10    client_id: ClientId,
11    //
12    token_endpoint_url: Url,
13    device_authorization_endpoint_url: Url,
14}
15impl GithubProviderWithDevice {
16    pub fn new(client_id: ClientId) -> Result<Self, UrlParseError> {
17        Ok(Self {
18            client_id,
19            token_endpoint_url: TOKEN_URL.parse()?,
20            device_authorization_endpoint_url: DEVICE_AUTHORIZATION_URL.parse()?,
21        })
22    }
23}
24impl Provider for GithubProviderWithDevice {
25    type Scope = GithubScope;
26
27    fn client_id(&self) -> Option<&ClientId> {
28        Some(&self.client_id)
29    }
30
31    fn client_secret(&self) -> Option<&ClientSecret> {
32        None
33    }
34
35    fn token_endpoint_url(&self) -> &Url {
36        &self.token_endpoint_url
37    }
38}
39impl ProviderExtDeviceAuthorizationGrant for GithubProviderWithDevice {
40    fn device_authorization_endpoint_url(&self) -> &Url {
41        &self.device_authorization_endpoint_url
42    }
43}