-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathyahoo-oauth.js
126 lines (107 loc) · 4.05 KB
/
yahoo-oauth.js
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
// [SNIPPET_REGISTRY disabled]
// [SNIPPETS_SEPARATION enabled]
// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/yahoo-oauth.md
function yahooProvider() {
// [START auth_yahoo_provider_create]
const { OAuthProvider } = require("firebase/auth");
const provider = new OAuthProvider('yahoo.com');
// [END auth_yahoo_provider_create]
// [START auth_yahoo_provider_scopes]
// Request access to Yahoo Mail API.
provider.addScope('mail-r');
// Request read/write access to user contacts.
// This must be preconfigured in the app's API permissions.
provider.addScope('sdct-w');
// [END auth_yahoo_provider_scopes]
// [START auth_yahoo_provider_params]
provider.setCustomParameters({
// Prompt user to re-authenticate to Yahoo.
prompt: 'login',
// Localize to French.
language: 'fr'
});
// [END auth_yahoo_provider_params]
}
function yahooSignInPopup(provider) {
// [START auth_yahoo_signin_popup]
const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth");
const auth = getAuth();
signInWithPopup(auth, provider)
.then((result) => {
// IdP data available in result.additionalUserInfo.profile
// ...
// Yahoo OAuth access token and ID token can be retrieved by calling:
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_signin_popup]
}
function yahooSignInRedirect(provider) {
// [START auth_yahoo_signin_redirect]
const { getAuth, signInWithRedirect } = require("firebase/auth");
const auth = getAuth();
signInWithRedirect(auth, provider);
// [END auth_yahoo_signin_redirect]
}
function yahooSigninRedirectResult() {
// [START auth_yahoo_signin_redirect_result]
const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth");
const auth = getAuth();
getRedirectResult(auth)
.then((result) => {
// IdP data available in result.additionalUserInfo.profile
// ...
// Yahoo OAuth access token and ID token can be retrieved by calling:
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_signin_redirect_result]
}
function yahooLinkPopup() {
// [START auth_yahoo_link_popup]
const { getAuth, linkWithPopup, OAuthProvider } = require("firebase/auth");
const provider = new OAuthProvider('yahoo.com');
const auth = getAuth();
linkWithPopup(auth.currentUser, provider)
.then((result) => {
// Yahoo credential is linked to the current user.
// IdP data available in result.additionalUserInfo.profile.
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_link_popup]
}
function yahooReauthPopup() {
// [START auth_yahoo_reauth_popup]
const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth");
const provider = new OAuthProvider('yahoo.com');
const auth = getAuth();
reauthenticateWithPopup(auth.currentUser, provider)
.then((result) => {
// User is re-authenticated with fresh tokens minted and
// should be able to perform sensitive operations like account
// deletion and email or password update.
// IdP data available in result.additionalUserInfo.profile.
// Get the OAuth access token and ID Token
const credential = OAuthProvider.credentialFromResult(result);
const accessToken = credential.accessToken;
const idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_reauth_popup]
}