11
11
< title > hello( github )</ title >
12
12
< h1 > hello( github )</ h1 >
13
13
14
- < button id ='github ' onclick ="login('github'); "> github</ button >
15
- < pre id ="result "> Signin to get a list of repos</ pre >
14
+ < button id ='github ' onclick ="profile('github'); "> Get Profile</ button >
16
15
< script class ="pre ">
17
- function login ( network ) {
18
-
16
+ function profile ( network ) {
19
17
var github = hello ( network ) ;
20
-
21
18
github . login ( ) . then ( function ( ) {
22
-
23
19
// get user profile data
24
- github . api ( 'me' ) . then ( function ( p ) {
25
- document . getElementById ( network ) . innerHTML = "<img src='" + p . thumbnail + "' width=24/>Connected to " + network + " as " + p . name ;
26
- } ) ;
20
+ return github . api ( 'me' ) ;
21
+ } )
22
+ . then ( function ( p ) {
23
+ document . getElementById ( network ) . innerHTML = "<img src='" + p . thumbnail + "' width=24/>Connected to " + network + " as " + p . name ;
24
+ } ) ;
25
+ }
26
+ </ script >
27
+
28
+ < h2 > Get user email</ h2 >
29
+
30
+ < button onclick ="userEmail('github', 'email'); "> Get email</ button >
31
+
32
+ < pre id ="email "> </ pre >
33
+ < script class ="pre ">
34
+ function userEmail ( network , target ) {
35
+ var github = hello ( network )
36
+ github . login ( {
37
+ scope :'email'
38
+ } )
39
+ . then ( function ( ) {
40
+ // Get a bespoke endpoint from github
41
+ return github . api ( '/user/emails' ) ;
42
+ } ) . then ( function ( r ) {
43
+ document . getElementById ( target ) . innerHTML = JSON . stringify ( r , null , 2 ) ;
44
+ } ) ;
45
+ }
46
+ </ script >
27
47
48
+ < h2 > List user repos</ h2 >
49
+
50
+ < button onclick ="userRepos('github', 'repo_list'); "> Get a list of repos</ button >
51
+
52
+ < pre id ="repo_list "> </ pre >
53
+ < script class ="pre ">
54
+ function userRepos ( network , target ) {
55
+ var github = hello ( network )
56
+ github . login ( )
57
+ . then ( function ( ) {
28
58
// Get a bespoke endpoint from github
29
- github . api ( '/user/repos' ) . then ( function ( r ) {
30
- document . getElementById ( 'result' ) . innerHTML = JSON . stringify ( r , null , 2 ) ;
31
- } ) ;
59
+ return github . api ( '/user/repos' ) ;
60
+ } ) . then ( function ( r ) {
61
+ document . getElementById ( target ) . innerHTML = JSON . stringify ( r , null , 2 ) ;
32
62
} ) ;
33
63
}
34
64
</ script >
@@ -38,6 +68,6 @@ <h1>hello( github )</h1>
38
68
github : GITHUB_CLIENT_ID
39
69
} , {
40
70
redirect_uri : '../redirect.html' ,
41
- oauth_proxy : OAUTH_PROXY_URL
71
+ // oauth_proxy : OAUTH_PROXY_URL
42
72
} ) ;
43
- </ script >
73
+ </ script >
0 commit comments