forked from fastify/fastify-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotify.js
More file actions
30 lines (26 loc) · 835 Bytes
/
spotify.js
File metadata and controls
30 lines (26 loc) · 835 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
25
26
27
28
29
30
const fastify = require('fastify')({ logger: true })
const oauthPlugin = require('fastify-oauth2')
fastify.register(oauthPlugin, {
name: 'Spotify',
scope: ['user-read-currently-playing'],
credentials: {
client: {
id: process.env.CLIENT_ID,
secret: process.env.CLIENT_SECRET
},
auth: oauthPlugin.SPOTIFY_CONFIGURATION
},
startRedirectPath: '/login/spotify',
callbackUri: `http://localhost:${process.env.PORT}/login/spotify/callback`
})
fastify.get('/login/spotify/callback', async (req, reply) => {
const token = await fastify.Spotify.getAccessTokenFromAuthorizationCodeFlow(req)
req.log.info('The Spotify token is %o', token)
reply.send({ access_token: token.access_token })
})
fastify.listen(process.env.PORT, (err) => {
if (err) {
fastify.log.error(err)
process.exit(1)
}
})