azure_identity/device_code_flow/
device_code_responses.rs

1use azure_core::auth::Secret;
2use serde::Deserialize;
3use std::fmt;
4
5/// Error response returned from the device code flow.
6#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
7pub struct DeviceCodeErrorResponse {
8    /// Name of the error.
9    pub error: String,
10    /// Description of the error.
11    pub error_description: String,
12    /// Uri to get more information on this error.
13    pub error_uri: String,
14}
15
16impl std::error::Error for DeviceCodeErrorResponse {}
17
18impl fmt::Display for DeviceCodeErrorResponse {
19    // This trait requires `fmt` with this exact signature.
20    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21        write!(f, "{}. {}", self.error, self.error_description)
22    }
23}
24
25/// A successful token response.
26#[derive(Debug, Clone, Deserialize)]
27pub struct DeviceCodeAuthorization {
28    /// Always `Bearer`.
29    pub token_type: String,
30    /// The scopes the access token is valid for.
31    /// Format: Space separated strings
32    pub scope: String,
33    /// Number of seconds the included access token is valid for.
34    pub expires_in: u64,
35    /// Issued for the scopes that were requested.
36    /// Format: Opaque string
37    access_token: Secret,
38    /// Issued if the original scope parameter included offline_access.
39    /// Format: JWT
40    refresh_token: Option<Secret>,
41    /// Issued if the original scope parameter included the openid scope.
42    /// Format: Opaque string
43    id_token: Option<Secret>,
44}
45
46impl DeviceCodeAuthorization {
47    /// Get the access token
48    pub fn access_token(&self) -> &Secret {
49        &self.access_token
50    }
51    /// Get the refresh token
52    pub fn refresh_token(&self) -> Option<&Secret> {
53        self.refresh_token.as_ref()
54    }
55    /// Get the id token
56    pub fn id_token(&self) -> Option<&Secret> {
57        self.id_token.as_ref()
58    }
59}