Я получаю ответ, который хочу, но маркер доступа, возвращенный из GitHub, возвращается без областей в ответе:
// githubs response
{
access_token: 'a2ed9606c8b06bf00a16dc34584b1509462450a4',
token_type: 'bearer',
scope: ''
}
Токен не может просматривать личные репозитории, как мой личный токен доступа с включенными областями. Я делаю что-то не так или не связываюсь с правильной конечной точкой?
// backend - Auth.js
var express = require('express');
var router = express.Router();
var fetch = require('isomorphic-fetch');
let token = null;
const createFetchOptions = (method, body = undefined) => {
const options = {
method,
headers: {
'Content-type': null,
'Accept': null,
},
};
options.headers['Content-type'] = 'application/json';
options.headers['Accept'] = 'application/json';
options.body = JSON.stringify(body);
return options;
};
const Fetcher = {
get: async (url) => {
const res =
await fetch(
url,
createFetchOptions('GET'),
);
return res;
},
post: async (url, body) => {
const res =
await fetch(
url,
createFetchOptions('POST', body),
);
return res;
},
}
router.post('/token', async (req, res) => {
const { clientId, clientSecret, sessionCode } = req.body;
const response = await Fetcher.post('https://github.com/login/oauth/access_token', {
client_id: clientId,
client_secret: clientSecret,
code: sessionCode,
});
const result = await response.json();
console.log(result)
res.json(result);
});
module.exports = router;