-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathgithub.js
88 lines (75 loc) · 2.79 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
// [SNIPPET_REGISTRY disabled]
// [SNIPPETS_SEPARATION enabled]
function githubProvider() {
// [START auth_github_provider_create]
const { GithubAuthProvider } = require("firebase/auth");
const provider = new 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]
const { GithubAuthProvider } = require("firebase/auth");
const credential = GithubAuthProvider.credential(token);
// [END auth_github_provider_credential]
}
function githubSignInPopup(provider) {
// [START auth_github_signin_popup]
const { getAuth, signInWithPopup, GithubAuthProvider } = require("firebase/auth");
const auth = getAuth();
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
const credential = GithubAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
// IdP data available using getAdditionalUserInfo(result)
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.customData.email;
// The AuthCredential type that was used.
const credential = GithubAuthProvider.credentialFromError(error);
// ...
});
// [END auth_github_signin_popup]
}
function githubSignInRedirectResult() {
// [START auth_github_signin_redirect_result]
const { getAuth, getRedirectResult, GithubAuthProvider } = require("firebase/auth");
const auth = getAuth();
getRedirectResult(auth)
.then((result) => {
const credential = GithubAuthProvider.credentialFromResult(result);
if (credential) {
// This gives you a GitHub Access Token. You can use it to access the GitHub API.
const token = credential.accessToken;
// ...
}
// The signed-in user info.
const user = result.user;
// IdP data available using getAdditionalUserInfo(result)
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.customData.email;
// The AuthCredential type that was used.
const credential = GithubAuthProvider.credentialFromError(error);
// ...
});
// [END auth_github_signin_redirect_result]
}