-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathyahoo-oauth.js
114 lines (101 loc) · 3.75 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
// These samples are intended for Web so this import would normally be
// done in HTML however using modules here is more convenient for
// ensuring sample correctness offline.
import firebase from "firebase/app";
import "firebase/auth";
// 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]
var provider = new firebase.auth.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]
firebase.auth().signInWithPopup(provider)
.then((result) => {
// IdP data available in result.additionalUserInfo.profile
// ...
/** @type {firebase.auth.OAuthCredential} */
const credential = result.credential;
// Yahoo OAuth access token and ID token can be retrieved by calling:
var accessToken = credential.accessToken;
var idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_signin_popup]
}
function yahooSignInRedirect(provider) {
// [START auth_yahoo_signin_redirect]
firebase.auth().signInWithRedirect(provider);
// [END auth_yahoo_signin_redirect]
}
function yahooSigninRedirectResult() {
// [START auth_yahoo_signin_redirect_result]
firebase.auth().getRedirectResult()
.then((result) => {
// IdP data available in result.additionalUserInfo.profile
// ...
/** @type {firebase.auth.OAuthCredential} */
const credential = result.credential;
// Yahoo OAuth access token and ID token can be retrieved by calling:
var accessToken = credential.accessToken;
var idToken = credential.idToken;
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_signin_redirect_result]
}
function yahooLinkPopup() {
// [START auth_yahoo_link_popup]
var provider = new firebase.auth.OAuthProvider('yahoo.com');
firebase.auth().currentUser.linkWithPopup(provider)
.then((result) => {
// Yahoo credential is linked to the current user.
// IdP data available in result.additionalUserInfo.profile.
// Yahoo OAuth access token can be retrieved by calling:
// result.credential.accessToken
// Yahoo OAuth ID token can be retrieved by calling:
// result.credential.idToken
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_link_popup]
}
function yahooReauthPopup() {
// [START auth_yahoo_reauth_popup]
var provider = new firebase.auth.OAuthProvider('yahoo.com');
firebase.auth().currentUser.reauthenticateWithPopup(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.
// Yahoo OAuth access token can be retrieved by calling:
// result.credential.accessToken
// Yahoo OAuth ID token can be retrieved by calling:
// result.credential.idToken
})
.catch((error) => {
// Handle error.
});
// [END auth_yahoo_reauth_popup]
}