Skip to content

Commit

Permalink
rework on github oauth start
Browse files Browse the repository at this point in the history
will not work due to isaacs/github#330
  • Loading branch information
sommerfe committed Sep 22, 2020
1 parent 0d38ef2 commit dcea912
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,56 @@ export class LoginComponent implements OnInit {
}
}else if(params.github == 'error'){
this.error = 'A Login error occured. Please try it again';
}
} else if (params.code){
const TOKEN_URL = 'https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token'
let data = new FormData()
data.append('client_id', '')
data.append('client_secret', '')
data.append('code', params.code)
console.log('code',params.code)
fetch(TOKEN_URL,
{
method: "POST",
mode: "cors",
body: data,
headers:{
'Access-Control-Allow-Origin': '*'
}
}).then((resp) => {
console.log(resp)
//console.log(resp.json())
return resp.json()
//let reader = resp.body.getReader()
//
//return reader.read()
//console.log(resp.body.getReader)
//return resp.body.json()
//console.log(await )
//const accessToken = resp.split("&")[0].split("=")[1];
//this.getGithubData(accessToken);
}
).then((r) => {
console.log('r',r)
})
}
})
}

getGithubData (accessToken){
fetch(`https://api.github.com/user?access_token=${accessToken}`,
{
method:"GET",
headers: {
"User-Agent": "SampleOAuth",
}
}).then(async function (resp) {
console.log(resp)
//let body = await JSON.parse(resp)

})

}

ngOnInit() {
}

Expand Down

0 comments on commit dcea912

Please sign in to comment.