-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathx.js
More file actions
34 lines (28 loc) · 940 Bytes
/
x.js
File metadata and controls
34 lines (28 loc) · 940 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
31
32
33
34
'use strict'
const fastify = require('fastify')({ logger: { level: 'trace' } })
// const oauthPlugin = require("@fastify/oauth2");
const oauthPlugin = require('..')
fastify.register(oauthPlugin, {
name: 'xOAuth2',
// See the full list of supported X OAuth2 scopes:
// https://docs.x.com/fundamentals/authentication/oauth-2-0/authorization-code#scopes
scope: ['users.read'],
credentials: {
client: {
id: '<CLIENT_ID>',
secret: '<CLIENT_SECRET>'
},
auth: oauthPlugin.X_CONFIGURATION,
},
startRedirectPath: '/login/x',
callbackUri: 'http://localhost:3000/login/x/callback',
// PKCE is required for X OAuth2 (`S256` or `plain`).
pkce: 'S256',
})
fastify.get('/login/x/callback', async function (request, reply) {
const { token } = await this.xOAuth2.getAccessTokenFromAuthorizationCodeFlow(
request
)
reply.send({ access_token: token.access_token })
})
fastify.listen({ port: 3000 })