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 11import React from 'react' ;
2+ import { Switch , Route } from 'react-router-dom'
3+
24import './App.css' ;
35import CoderockrLogo from './assets/images/hand-yellow.svg'
46import Home from './Home'
57import Footer from './Footer' ;
6- import { Switch , Route } from 'react-router-dom'
8+ import GitHub from './GitHub/GitHub' ;
79
810const App = ( ) => (
911 < div className = "CWSPApp" >
@@ -16,6 +18,7 @@ const App = () => (
1618 < div className = " container" >
1719 < Switch >
1820 < Route exact path = "/" component = { Home } />
21+ < Route path = "/github/" component = { GitHub } />
1922 </ Switch >
2023 </ div >
2124 < 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'
55import gitlabLogo from './assets/images/gitlab.svg'
66import trelloLogo from './assets/images/trello.svg'
77import './Home.css'
8+ import { githubAuthorizeUrl } from './GitHub/constants' ;
89
910const callbackUrl = ( setupable ) => `${ window . location . href } ${ setupable } /callback`
1011const SETUPABLE = [
1112 {
1213 name : "GitHub" ,
1314 logo : githubLogo ,
1415 enabled : true ,
15- url : 'https://github.com/login/oauth/authorize?client_id=0e8a63320fba47de145c&scope=repos&redirect_uri=' + callbackUrl ( 'github' ) ,
16+ url : githubAuthorizeUrl ( callbackUrl ( 'github' ) ) ,
1617 } ,
1718 {
1819 name : "GitLab" ,
You can’t perform that action at this time.
0 commit comments