-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathgithub.js
87 lines (77 loc) · 2.67 KB
/
github.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
// 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";
function githubProvider() {
// [START auth_github_provider_create]
var provider = new firebase.auth.GithubAuthProvider();
// [END auth_github_provider_create]
// [START auth_github_provider_scopes]
provider.addScope('repo');
// [END auth_github_provider_scopes]
// [START auth_github_provider_params]
provider.setCustomParameters({
'allow_signup': 'false'
});
// [END auth_github_provider_params]
}
function githubProviderCredential(token) {
// [START auth_github_provider_credential]
var credential = firebase.auth.GithubAuthProvider.credential(token);
// [END auth_github_provider_credential]
}
function githubSignInPopup(provider) {
// [START auth_github_signin_popup]
firebase
.auth()
.signInWithPopup(provider)
.then((result) => {
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
var token = credential.accessToken;
// The signed-in user info.
var user = result.user;
// IdP data available in result.additionalUserInfo.profile.
// ...
}).catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
// [END auth_github_signin_popup]
}
function githubSignInRedirectResult() {
// [START auth_github_signin_redirect_result]
firebase.auth()
.getRedirectResult()
.then((result) => {
if (result.credential) {
/** @type {firebase.auth.OAuthCredential} */
var credential = result.credential;
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
var token = credential.accessToken;
// ...
}
// The signed-in user info.
var user = result.user;
// IdP data available in result.additionalUserInfo.profile.
// ...
}).catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
// [END auth_github_signin_redirect_result]
}