-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathspotify.js
More file actions
29 lines (23 loc) · 834 Bytes
/
spotify.js
File metadata and controls
29 lines (23 loc) · 834 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
'use strict'
const fastify = require('fastify')({ logger: true })
// const oauthPlugin = require('fastify-oauth2')
const oauthPlugin = require('..')
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 result = await fastify.Spotify.getAccessTokenFromAuthorizationCodeFlow(req)
req.log.info('The Spotify token is %o', result.token)
reply.send({ access_token: result.token.access_token })
})
fastify.listen({ port: process.env.PORT })