File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ const fastify = require ( 'fastify' ) ( { logger : { level : 'trace' } } )
2
+ const oauthPlugin = require ( 'fastify-oauth2' )
3
+
4
+ fastify . register ( oauthPlugin , {
5
+ name : 'vkOAuth2' ,
6
+ scope : [ 'email' ] ,
7
+ credentials : {
8
+ client : {
9
+ id : process . env . CLIENT_ID ,
10
+ secret : process . env . CLIENT_SECRET
11
+ } ,
12
+ auth : oauthPlugin . VKONTAKTE_CONFIGURATION
13
+ } ,
14
+ startRedirectPath : '/login/vk' ,
15
+ callbackUri : `http://localhost:${ process . env . PORT } /login/vk/callback`
16
+ } )
17
+
18
+ fastify . get ( '/login/vk/callback' , async ( req , reply ) => {
19
+ const token = await fastify . getAccessTokenFromAuthorizationCodeFlow ( req )
20
+
21
+ console . log ( token )
22
+ reply . send ( { access_token : token . access_token } )
23
+ } )
24
+
25
+ fastify . listen ( process . env . PORT , ( err , address ) => {
26
+ if ( err ) {
27
+ fastify . log . error ( err )
28
+ process . exit ( 1 )
29
+ }
30
+ fastify . log . info ( `server listening on ${ address } ` )
31
+ } )
Original file line number Diff line number Diff line change @@ -159,4 +159,11 @@ oauthPlugin.MICROSOFT_CONFIGURATION = {
159
159
tokenPath : '/common/oauth2/v2.0/token'
160
160
}
161
161
162
+ oauthPlugin . VKONTAKTE_CONFIGURATION = {
163
+ authorizeHost : 'https://oauth.vk.com' ,
164
+ authorizePath : '/authorize' ,
165
+ tokenHost : 'https://oauth.vk.com' ,
166
+ tokenPath : '/access_token'
167
+ }
168
+
162
169
module . exports = oauthPlugin
You can’t perform that action at this time.
0 commit comments