-
Notifications
You must be signed in to change notification settings - Fork 0
/
devServer.ts
38 lines (30 loc) · 1 KB
/
devServer.ts
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
35
36
37
38
import * as fastify from 'fastify';
import { Server, IncomingMessage, ServerResponse } from 'http';
import { inspect } from 'util';
import fetch from 'node-fetch';
import LinkedInAuthClient from '../dist';
const linkedInAuthClient = new LinkedInAuthClient({ fetchProvider: fetch });
linkedInAuthClient.init({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
redirect_uri: process.env.REDIRECT_URI,
scope: ['r_liteprofile', 'r_emailaddress'],
response_type: 'code',
grant_type: 'authorization_code'
});
const server: fastify.FastifyInstance<
Server,
IncomingMessage,
ServerResponse
> = fastify();
server.get('/', async (request, reply) => {
reply.redirect(linkedInAuthClient.getAuthorizationUrl());
});
server.get('/auth', async (request, reply) => {
const data = await linkedInAuthClient.getAccessToken(request.query.code);
reply
.code(200)
.header('Content-Type', 'text/html')
.send(`<h1>Success</h1><pre>${inspect(data)}</pre>`);
});
server.listen(8000);