Для начала вам необходимо создать ссылку авторизации для пользователя, используя ваш Идентификатор клиента приложения:
Код: Выделить всё
const crypto = require('crypto');
const clientID = process.env.BNG_CLIENT_ID;
const authURL = 'https://www.bungie.net/en/oauth/authorize';
// Create authorization link.
const authState = crypto.randomBytes(20).toString('hex');
console.log(`${authURL}?client_id=${clientID}&response_type=code&state=${authState}`);
Здесь я застрял:
Код: Выделить всё
const clientSecret = process.env.BNG_CLIENT_SECRET;
const tokenURL = 'https://www.bungie.net/platform/app/oauth/token';
const authCode = 'The authentication code :)';
fetch(tokenURL, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${btoa(`${clientID}:${clientSecret}`)}`
},
body: new URLSearchParams({
'client_id': clientID,
'grant_type': 'authorization_code',
'code': authCode
}).toString()
}).then(res => {
console.log(res);
return res.json();
});
Уже пробовал использовать client_id и client_secret в качестве параметра запроса. непосредственно в строку вместо использования заголовка Authorization, то же самое.
Подробнее здесь: https://stackoverflow.com/questions/793 ... in-node-js
Мобильная версия