oauth2_microsoft/
device_authorization_grant.rs1use oauth2_client::{
2 re_exports::{ClientId, ClientSecret, Url, UrlParseError},
3 Provider, ProviderExtDeviceAuthorizationGrant,
4};
5
6use crate::{device_authorization_url, token_url, MicrosoftScope};
7
8#[derive(Debug, Clone)]
9pub struct MicrosoftProviderForDevices {
10 client_id: ClientId,
11 token_endpoint_url: Url,
13 device_authorization_endpoint_url: Url,
14}
15impl MicrosoftProviderForDevices {
16 pub fn new(tenant: impl AsRef<str>, client_id: ClientId) -> Result<Self, UrlParseError> {
17 Ok(Self {
18 client_id,
19 token_endpoint_url: token_url(tenant.as_ref()).parse()?,
20 device_authorization_endpoint_url: device_authorization_url(tenant.as_ref()).parse()?,
21 })
22 }
23}
24impl Provider for MicrosoftProviderForDevices {
25 type Scope = MicrosoftScope;
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 MicrosoftProviderForDevices {
40 fn device_authorization_endpoint_url(&self) -> &Url {
41 &self.device_authorization_endpoint_url
42 }
43}