|
1 |
| -const fastify = require('fastify')({ logger: { level: 'trace' } }); |
2 |
| -const oauthPlugin = require('fastify-oauth2'); |
| 1 | +const fastify = require('fastify')({ logger: { level: 'trace' } }) |
| 2 | +const oauthPlugin = require('fastify-oauth2') |
3 | 3 |
|
4 | 4 | fastify.register(oauthPlugin, {
|
5 |
| - name : 'vkOAuth2', |
6 |
| - scope : ['email'], |
| 5 | + name: 'vkOAuth2', |
| 6 | + scope: ['email'], |
7 | 7 | credentials: {
|
8 | 8 | client: {
|
9 |
| - id : process.env.CLIENT_ID, |
10 |
| - secret : process.env.CLIENT_SECRET |
| 9 | + id: process.env.CLIENT_ID, |
| 10 | + secret: process.env.CLIENT_SECRET |
11 | 11 | },
|
12 |
| - auth : oauthPlugin.VKONTAKTE_CONFIGURATION |
| 12 | + auth: oauthPlugin.VKONTAKTE_CONFIGURATION |
13 | 13 | },
|
14 | 14 | startRedirectPath: '/login/vk',
|
15 | 15 | callbackUri: `http://localhost:${process.env.PORT}/login/vk/callback`
|
16 |
| -}); |
| 16 | +}) |
17 | 17 |
|
18 | 18 | fastify.get('/login/vk/callback', async (req, reply) => {
|
19 |
| - const token = await fastify.getAccessTokenFromAuthorizationCodeFlow(req); |
| 19 | + const token = await fastify.getAccessTokenFromAuthorizationCodeFlow(req) |
20 | 20 |
|
21 |
| - console.log(token); |
22 |
| - reply.send({ access_token: token.access_token }); |
23 |
| -}); |
| 21 | + console.log(token) |
| 22 | + reply.send({ access_token: token.access_token }) |
| 23 | +}) |
24 | 24 |
|
25 | 25 | fastify.listen(process.env.PORT, (err, address) => {
|
26 | 26 | if (err) {
|
27 |
| - fastify.log.error(err); |
28 |
| - process.exit(1); |
| 27 | + fastify.log.error(err) |
| 28 | + process.exit(1) |
29 | 29 | }
|
30 |
| - fastify.log.info(`server listening on ${address}`); |
31 |
| -}); |
| 30 | + fastify.log.info(`server listening on ${address}`) |
| 31 | +}) |
0 commit comments