-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (46 loc) · 1.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const
express = require('express'),
axios = require('axios'),
querystring = require('querystring');
const
CLIENT_ID = 'your client id',
CLIENT_SECRET = 'your client secret'
const app = express();
app.use(
express.json(),
express.urlencoded({ extended: false })
);
app.get('/auth/overwolf/callback', function(req, res, next) {
if ( !req.query.code ) {
res.send('error');
return;
}
axios.post('https://accounts.overwolf.com/oauth2/token',
querystring.stringify({
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
grant_type: 'authorization_code',
code: req.query.code,
redirect_uri: 'http://localhost:8080/auth/overwolf/callback'
}),
{
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}).then(function(response) {
// the response will contain the access token to be used
if ( response.data.access_token ) {
res.redirect(`http://localhost:3000/login-success?${querystring.stringify(response.data)}`);
} else {
console.error(response.data);
res.send('');
}
}).catch((e) => {
console.error(e.response.data);
res.send('error');
});
});
app.get('/', function(req, res, next) {
res.send('');
});
module.exports = app;