-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (29 loc) · 919 Bytes
/
server.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
32
33
34
35
const { OAuth2Server } = require('oauth2-mock-server')
global.atob = require('atob');
async function startServer() {
const server = new OAuth2Server()
await server.issuer.keys.generateRSA();
await server.start(8080, 'localhost');
return server.service
}
startServer()
.then((service) => {
service.on('beforeUserinfo', (userInfoResponse, req) => {
const email = parseTestEmail(req.query.state);
userInfoResponse.body = {
"email": email !== null ? email : "[email protected]",
"firstName": "Party",
"lastName": "Pete",
}
})
})
.catch((e) => console.log('Something went wrong starting the server: ', e))
function parseTestEmail(state) {
try {
const stateStr = atob(state)
const stateObj = JSON.parse(stateStr);
return typeof stateObj.testEmail !== 'undefined' ? stateObj.testEmail : null;
} catch (e) {
return null;
}
}