1
+ <!-- https://www.codigofonte.com.br/codigos/autenticacao-atraves-do-github-com-javascript-e-oauth -->
2
+ < html >
3
+ < header >
4
+ < script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css "> </ script >
5
+ < script src ="https://code.jquery.com/jquery-3.2.1.min.js "> </ script >
6
+ < script src ="https://cdn.rawgit.com/oauth-io/oauth-js/c5af4519/dist/oauth.js "> </ script >
7
+ < link rel ="stylesheet " href ="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css ">
8
+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-social/4.12.0/bootstrap-social.min.css ">
9
+ </ header >
10
+
11
+ < body >
12
+ < a id ="github-button " class ="btn btn-block btn-social btn-github ">
13
+ < i class ="fa fa-github "> </ i > Sign in with Github
14
+ </ a >
15
+
16
+ < script >
17
+ $ ( '#github-button' ) . on ( 'click' , function ( ) {
18
+ // Inicialize com a sua chave publica de autenticação do app OAuth.io
19
+ OAuth . initialize ( 'SUA_OAUTH_KEY' ) ;
20
+ // Use pop-up para oauth
21
+ // Ou Redirecionamento
22
+ OAuth . popup ( 'github' ) . then ( github => {
23
+ console . log ( 'github:' , github ) ;
24
+ // Recupera dados do usuário do provedor oauth
25
+ // Para login bem sucessedido, retorna a mensagem de Bem Vindo
26
+ // #me() é um método para recuperar dados do usuário
27
+ // para saber qual URL do provedor OAuth chamar
28
+ github . me ( ) . then ( data => {
29
+ console . log ( 'me data:' , data ) ;
30
+ alert ( 'GitHub seu email é:' + data . email + ".\nAcesse 'Console Log' para mais detalhes" ) ;
31
+ } ) ;
32
+ // Recupera dados do usuário do provedor OAuth usando #get () e
33
+ // URL do provedor OAuth
34
+ github . get ( '/user' ) . then ( data => {
35
+ console . log ( 'self data:' , data ) ;
36
+ } )
37
+ } ) ;
38
+ } )
39
+ </ script >
40
+ </ body >
41
+ </ html >
0 commit comments