actix_firebase_auth/firebase/user.rs
1use email_address::EmailAddress;
2use serde::{Deserialize, Serialize};
3use serde_json::{Map, Value};
4use url::Url;
5
6/// Represents the decoded JWT claims from a Firebase Authentication token.
7///
8/// This struct maps to the standard fields provided by Firebase ID tokens.
9/// See: <https://firebase.google.com/docs/auth/admin/verify-id-tokens#verify_id_tokens_using_a_third-party_jwt_library>
10#[derive(Clone, Debug, Serialize, Deserialize)]
11pub struct FirebaseUser {
12 /// Issuer of the token (typically Firebase project URL)
13 pub iss: String,
14
15 /// Audience for the token (your Firebase project ID)
16 pub aud: String,
17
18 /// Subject — the unique identifier for the user (usually equals `user_id`)
19 pub sub: String,
20
21 /// Issued-at time (epoch seconds)
22 pub iat: u64,
23
24 /// Expiration time (epoch seconds)
25 pub exp: u64,
26
27 /// Time the user authenticated (epoch seconds)
28 pub auth_time: u64,
29
30 /// Firebase UID of the user
31 pub user_id: String,
32
33 /// The identity provider used to sign in (e.g., "google.com")
34 pub provider_id: Option<String>,
35
36 /// User's display name (if available)
37 pub name: Option<String>,
38
39 /// URL to the user's profile picture (if available)
40 pub picture: Option<Url>,
41
42 /// User's email address
43 pub email: Option<EmailAddress>,
44
45 /// Whether the user's email has been verified
46 pub email_verified: Option<bool>,
47
48 /// Additional Firebase-specific claims (provider info, linked accounts)
49 pub firebase: FirebaseProvider,
50}
51
52/// Firebase-specific metadata included in the token under the `firebase` field.
53///
54/// This contains provider info and linked account identities (e.g., Google UID).
55#[derive(Clone, Debug, Serialize, Deserialize)]
56pub struct FirebaseProvider {
57 /// The main sign-in provider used (e.g., "google.com", "password")
58 pub sign_in_provider: String,
59
60 /// A map of identity providers to a list of unique IDs (e.g., `{ "google.com": ["1234567890"] }`)
61 pub identities: Map<String, Value>,
62}