Skip to main content

browser_protocol/fedcm/
mod.rs

1//! This domain allows interacting with the FedCM dialog.
2
3use serde::{Serialize, Deserialize};
4
5/// Whether this is a sign-up or sign-in action for this account, i.e.
6/// whether this account has ever been used to sign in to this RP before.
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
9pub enum LoginState {
10    #[default]
11    SignIn,
12    SignUp,
13}
14
15/// The types of FedCM dialogs.
16
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
18pub enum DialogType {
19    #[default]
20    AccountChooser,
21    AutoReauthn,
22    ConfirmIdpLogin,
23    Error,
24}
25
26/// The buttons on the FedCM dialog.
27
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
29pub enum DialogButton {
30    #[default]
31    ConfirmIdpLoginContinue,
32    ErrorGotIt,
33    ErrorMoreDetails,
34}
35
36/// The URLs that each account has
37
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
39pub enum AccountUrlType {
40    #[default]
41    TermsOfService,
42    PrivacyPolicy,
43}
44
45/// Corresponds to IdentityRequestAccount
46
47#[derive(Debug, Clone, Serialize, Deserialize, Default)]
48#[serde(rename_all = "camelCase")]
49pub struct Account {
50
51    pub accountId: String,
52
53    pub email: String,
54
55    pub name: String,
56
57    pub givenName: String,
58
59    pub pictureUrl: String,
60
61    pub idpConfigUrl: String,
62
63    pub idpLoginUrl: String,
64
65    pub loginState: LoginState,
66    /// These two are only set if the loginState is signUp
67
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub termsOfServiceUrl: Option<String>,
70
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub privacyPolicyUrl: Option<String>,
73}
74
75
76#[derive(Debug, Clone, Serialize, Deserialize, Default)]
77#[serde(rename_all = "camelCase")]
78pub struct EnableParams {
79    /// Allows callers to disable the promise rejection delay that would
80    /// normally happen, if this is unimportant to what's being tested.
81    /// (step 4 of <https://fedidcg.github.io/FedCM/#browser-api-rp-sign-in>)
82
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub disableRejectionDelay: Option<bool>,
85}
86
87
88#[derive(Debug, Clone, Serialize, Deserialize, Default)]
89#[serde(rename_all = "camelCase")]
90pub struct SelectAccountParams {
91
92    pub dialogId: String,
93
94    pub accountIndex: u64,
95}
96
97
98#[derive(Debug, Clone, Serialize, Deserialize, Default)]
99#[serde(rename_all = "camelCase")]
100pub struct ClickDialogButtonParams {
101
102    pub dialogId: String,
103
104    pub dialogButton: DialogButton,
105}
106
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
109#[serde(rename_all = "camelCase")]
110pub struct OpenUrlParams {
111
112    pub dialogId: String,
113
114    pub accountIndex: u64,
115
116    pub accountUrlType: AccountUrlType,
117}
118
119
120#[derive(Debug, Clone, Serialize, Deserialize, Default)]
121#[serde(rename_all = "camelCase")]
122pub struct DismissDialogParams {
123
124    pub dialogId: String,
125
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub triggerCooldown: Option<bool>,
128}