Skip to main content

authkestra_core/
state.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5/// A unified identity structure returned by all providers.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Identity {
8    /// The provider identifier (e.g., "github", "google")
9    pub provider_id: String,
10    /// The unique ID of the user within the provider's system
11    pub external_id: String,
12    /// The user's email address, if available and authorized
13    pub email: Option<String>,
14    /// The user's username or display name, if available
15    pub username: Option<String>,
16    /// Additional provider-specific attributes
17    pub attributes: HashMap<String, String>,
18}
19
20/// Represents the tokens returned by an OAuth2 provider.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct OAuthToken {
23    /// The access token used for API requests
24    pub access_token: String,
25    /// The type of token (usually "Bearer")
26    pub token_type: String,
27    /// Seconds until the access token expires
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub expires_in: Option<u64>,
30    /// The refresh token used to obtain new access tokens
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub refresh_token: Option<String>,
33    /// The scopes granted by the user
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub scope: Option<String>,
36    /// The OIDC ID Token
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub id_token: Option<String>,
39}