Guys I have an error that in my NodeJS rest API, and can not resolve this. My idea is to do a github login, this application works like this:
-
Redirection to github by returning a temporary code in callback.
-
Send this temporary code to my REST API and make a search request to another endpoint of the GitHub API. This request must return
access_token = 12345
(this access token is an example), to send this token to the frontend, convert it to a JWT token and then store it in a localStorage to use it.
My code in NodeJS
router.post("/users/github/:code",function(req,res){
fetch('https://github.com/login/oauth/access_token/', {
method: 'GET',
client_id: 'xxxx',
client_secret: 'xxxx',
code: req.params.code,
accept: 'json',
})
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
});
PS: I use% co_of% module for this. link