-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.js
More file actions
24 lines (23 loc) · 794 Bytes
/
Copy pathcallback.js
File metadata and controls
24 lines (23 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import fetch from "node-fetch";
const callback = async (req,res,next)=>{
const code = req.query.code || null;
var body = {
code: code,
redirect_uri: process.env.REDIRECT_URI,
grant_type: 'authorization_code'
}
await fetch('https://accounts.spotify.com/api/token',{
method: 'post',
body: new URLSearchParams(body),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + (Buffer.from(process.env.CLIENT_ID + ':' + process.env.CLIENT_SECRET).toString('base64'))
}
})
.then(resp => resp.json())
.then(data => {
res.redirect(`/?${new URLSearchParams(data)}`);
});
}
export default callback;