Untitled
unknown
plain_text
2 years ago
1.6 kB
10
Indexable
const express = require('express');
const axios = require('axios');
const app = express();
const port = 3000;
// Replace with your Battle.net API credentials
const clientId = 'YOUR_CLIENT_ID';
const clientSecret = 'YOUR_CLIENT_SECRET';
const redirectUri = 'http://localhost:3000/callback';
app.get('/callback', async (req, res) => {
const authorizationCode = req.query.code;
try {
// Exchange the authorization code for an access token
const response = await axios.post('https://us.battle.net/oauth/token', null, {
params: {
client_id: clientId,
client_secret: clientSecret,
code: authorizationCode,
redirect_uri: redirectUri,
grant_type: 'authorization_code',
},
});
const accessToken = response.data.access_token;
// You can now use the accessToken to make authenticated requests to the Battle.net API
// For example, you can fetch the user's Battle.net account information
const userInfoResponse = await axios.get('https://us.battle.net/oauth/userinfo', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const userInfo = userInfoResponse.data;
// Handle the user's information or perform any other desired actions
res.send(`Logged in as ${userInfo.battletag}`);
} catch (error) {
console.error('Error:', error.message);
res.status(500).send('An error occurred');
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});Editor is loading...