File tree Expand file tree Collapse file tree 5 files changed +96
-2
lines changed Expand file tree Collapse file tree 5 files changed +96
-2
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import { Switch , Route } from 'react-router-dom'
3
+
2
4
import './App.css' ;
3
5
import CoderockrLogo from './assets/images/hand-yellow.svg'
4
6
import Home from './Home'
5
7
import Footer from './Footer' ;
6
- import { Switch , Route } from 'react-router-dom'
8
+ import GitHub from './GitHub/GitHub' ;
7
9
8
10
const App = ( ) => (
9
11
< div className = "CWSPApp" >
@@ -16,6 +18,7 @@ const App = () => (
16
18
< div className = " container" >
17
19
< Switch >
18
20
< Route exact path = "/" component = { Home } />
21
+ < Route path = "/github/" component = { GitHub } />
19
22
</ Switch >
20
23
</ div >
21
24
< Footer />
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { Progress } from 'reactstrap'
3
+
4
+ const Loading = ( ) => (
5
+ < Progress animated color = "primary" striped value = { 100 } />
6
+ ) ;
7
+
8
+ export default Loading
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import Loading from '../Components/Loading' ;
3
+ import { githubAccessTokenUrl } from './constants'
4
+
5
+ class GitHub extends React . Component {
6
+ constructor ( props ) {
7
+ super ( props ) ;
8
+
9
+ const params = new URLSearchParams ( props . location . search ) ;
10
+
11
+ this . state = {
12
+ loading : true ,
13
+ code : params . get ( 'code' )
14
+ } ;
15
+ }
16
+
17
+ async componentDidMount ( ) {
18
+ fetch ( new Request (
19
+ 'https://api.github.com/users/lucassabreu' ,
20
+ {
21
+ method : "GET" ,
22
+ headers : new Headers ( { accept : 'application/json' } )
23
+ } )
24
+ )
25
+ . then ( r => r . json ( ) )
26
+ . then ( console . log )
27
+
28
+ fetch ( new Request (
29
+ githubAccessTokenUrl ( this . state . code ) ,
30
+ {
31
+ method : 'POST' ,
32
+ headers : new Headers ( { Accept : 'application/json' } )
33
+ }
34
+ ) )
35
+ . then ( r => {
36
+ if ( r . ok === false ) {
37
+ throw new Error ( `${ r . status } - ${ r . statusText } ` )
38
+ }
39
+ return r . json ( )
40
+ } )
41
+ . then ( console . log ( ) )
42
+ }
43
+
44
+ render ( ) {
45
+ const { loading } = this . state ;
46
+ return (
47
+ < div className = "GitHub" >
48
+ { loading ?
49
+ < section >
50
+ < h2 > Loading...</ h2 >
51
+ < Loading />
52
+ </ section >
53
+ :
54
+ < section >
55
+ </ section >
56
+ }
57
+ </ div >
58
+ )
59
+ }
60
+ }
61
+
62
+ export default GitHub
Original file line number Diff line number Diff line change
1
+ const GITHUB_CLIENT_ID = '0e8a63320fba47de145c' ;
2
+ const GITHUB_CLIENT_SECRET = '<it will not work anyway>' ;
3
+
4
+ const githubAccessTokenUrl = ( code ) => (
5
+ `https://github.com/login/oauth/access_token?client_id=${ GITHUB_CLIENT_ID } &client_secret=${ GITHUB_CLIENT_SECRET } &code=${ code } `
6
+ ) ;
7
+
8
+ const githubAuthorizeUrl = ( callback ) => (
9
+ `https://github.com/login/oauth/authorize?client_id=${ GITHUB_CLIENT_ID } &scope=repos&redirect_uri=${ callback } `
10
+ )
11
+
12
+ export {
13
+ GITHUB_CLIENT_ID ,
14
+ GITHUB_CLIENT_SECRET ,
15
+ githubAccessTokenUrl ,
16
+ githubAuthorizeUrl ,
17
+ }
18
+
19
+
20
+
Original file line number Diff line number Diff line change @@ -5,14 +5,15 @@ import githubLogo from './assets/images/github.svg'
5
5
import gitlabLogo from './assets/images/gitlab.svg'
6
6
import trelloLogo from './assets/images/trello.svg'
7
7
import './Home.css'
8
+ import { githubAuthorizeUrl } from './GitHub/constants' ;
8
9
9
10
const callbackUrl = ( setupable ) => `${ window . location . href } ${ setupable } /callback`
10
11
const SETUPABLE = [
11
12
{
12
13
name : "GitHub" ,
13
14
logo : githubLogo ,
14
15
enabled : true ,
15
- url : 'https://github.com/login/oauth/authorize?client_id=0e8a63320fba47de145c&scope=repos&redirect_uri=' + callbackUrl ( 'github' ) ,
16
+ url : githubAuthorizeUrl ( callbackUrl ( 'github' ) ) ,
16
17
} ,
17
18
{
18
19
name : "GitLab" ,
You can’t perform that action at this time.
0 commit comments