azure_identity/device_code_flow/
device_code_responses.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use azure_core::auth::Secret;
use serde::Deserialize;
use std::fmt;

/// Error response returned from the device code flow.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct DeviceCodeErrorResponse {
    /// Name of the error.
    pub error: String,
    /// Description of the error.
    pub error_description: String,
    /// Uri to get more information on this error.
    pub error_uri: String,
}

impl std::error::Error for DeviceCodeErrorResponse {}

impl fmt::Display for DeviceCodeErrorResponse {
    // This trait requires `fmt` with this exact signature.
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}. {}", self.error, self.error_description)
    }
}

/// A successful token response.
#[derive(Debug, Clone, Deserialize)]
pub struct DeviceCodeAuthorization {
    /// Always `Bearer`.
    pub token_type: String,
    /// The scopes the access token is valid for.
    /// Format: Space separated strings
    pub scope: String,
    /// Number of seconds the included access token is valid for.
    pub expires_in: u64,
    /// Issued for the scopes that were requested.
    /// Format: Opaque string
    access_token: Secret,
    /// Issued if the original scope parameter included offline_access.
    /// Format: JWT
    refresh_token: Option<Secret>,
    /// Issued if the original scope parameter included the openid scope.
    /// Format: Opaque string
    id_token: Option<Secret>,
}

impl DeviceCodeAuthorization {
    /// Get the access token
    pub fn access_token(&self) -> &Secret {
        &self.access_token
    }
    /// Get the refresh token
    pub fn refresh_token(&self) -> Option<&Secret> {
        self.refresh_token.as_ref()
    }
    /// Get the id token
    pub fn id_token(&self) -> Option<&Secret> {
        self.id_token.as_ref()
    }
}