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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use serde::Serialize;
use crate::ProviderId;
/// Post body for ID providers contains the OAuth credential and provider ID.
#[derive(Clone, Debug)]
pub enum IdpPostBody {
/// Apple OAuth.
///
/// Refers to the [document](https://developer.apple.com/documentation/devicemanagement/user_enrollment/onboarding_users_with_account_sign-in/implementing_the_oauth2_authentication_user-enrollment_flow).
Apple {
access_token: String,
},
/// Google OAuth.
///
/// Refers to the [document](https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential).
Google {
/// OpenID Connect ID token.
id_token: String,
},
/// Facebook OAuth.
///
/// Refers to the [document](https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential).
Facebook {
access_token: String,
},
/// Twitter OAuth.
///
/// Refers to the [document](https://firebase.google.com/docs/reference/rest/auth#section-sign-in-with-oauth-credential).
Twitter {
access_token: String,
oauth_token_secret: String,
},
/// GitHub OAuth.
///
/// Refers to the [document](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps).
GitHub {
access_token: String,
},
/// Microsoft OAuth.
///
/// Refers to the [document](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow).
Microsoft {
access_token: String,
},
/// Yahoo OAuth.
///
/// Refers to the [document](https://developer.yahoo.com/oauth2/guide/flows_authcode/).
Yahoo {
access_token: String,
},
/// LinkedIn OAuth.
///
/// Refers to the [document](https://www.linkedin.com/pulse/oauth2-amit-nadiger/).
LinkedIn {
access_token: String,
},
}
impl Serialize for IdpPostBody {
fn serialize<S>(
&self,
serializer: S,
) -> std::result::Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let post_body = match self {
| IdpPostBody::Apple {
access_token,
} => {
format!(
"access_token={}&providerId={}",
access_token,
ProviderId::Apple.format(),
)
},
| IdpPostBody::Google {
id_token,
} => {
format!(
"id_token={}&providerId={}",
id_token,
ProviderId::Google.format(),
)
},
| IdpPostBody::Facebook {
access_token,
} => {
format!(
"access_token={}&providerId={}",
access_token,
ProviderId::Facebook.format(),
)
},
| IdpPostBody::Twitter {
access_token,
oauth_token_secret,
} => {
format!(
"access_token={}&oauth_token_secret={}&providerId={}",
access_token,
oauth_token_secret,
ProviderId::Twitter.format(),
)
},
| IdpPostBody::GitHub {
access_token,
} => {
format!(
"access_token={}&providerId={}",
access_token,
ProviderId::GitHub.format(),
)
},
| IdpPostBody::Microsoft {
access_token,
} => {
format!(
"access_token={}&providerId={}",
access_token,
ProviderId::Microsoft.format(),
)
},
| IdpPostBody::Yahoo {
access_token,
} => {
format!(
"access_token={}&providerId={}",
access_token,
ProviderId::Yahoo.format(),
)
},
| IdpPostBody::LinkedIn {
access_token,
} => {
format!(
"access_token={}&providerId={}",
access_token,
ProviderId::LinkedIn.format(),
)
},
};
serializer.serialize_str(post_body.as_str())
}
}