forked from fastify/fastify-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vkontakte.js
31 lines (27 loc) · 850 Bytes
/
vkontakte.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
const fastify = require('fastify')({ logger: { level: 'trace' } })
const oauthPlugin = require('fastify-oauth2')
fastify.register(oauthPlugin, {
name: 'vkOAuth2',
scope: ['email'],
credentials: {
client: {
id: process.env.CLIENT_ID,
secret: process.env.CLIENT_SECRET
},
auth: oauthPlugin.VKONTAKTE_CONFIGURATION
},
startRedirectPath: '/login/vk',
callbackUri: `http://localhost:${process.env.PORT}/login/vk/callback`
})
fastify.get('/login/vk/callback', async (req, reply) => {
const token = await fastify.vkOAuth2.getAccessTokenFromAuthorizationCodeFlow(req)
console.log(token)
reply.send({ access_token: token.access_token })
})
fastify.listen(process.env.PORT, (err, address) => {
if (err) {
fastify.log.error(err)
process.exit(1)
}
fastify.log.info(`server listening on ${address}`)
})