-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmock-server.js
72 lines (59 loc) · 2.24 KB
/
mock-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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//https://github.com/axa-group/oauth2-mock-server
const { OAuth2Server } = require('oauth2-mock-server');
let server = new OAuth2Server();
// catching signals and do something before exit
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
].forEach(function (sig) {
process.on(sig, function () {
//console.log("Caught interrupt signal");
// Stop the server
StopServer().then(() => process.exit());
});
});
async function Main() {
await StartServer(server);
// server.service.on('beforeTokenSigning', (token, _req) => {
// token.payload.client_id = "sample-app";
// });
// Modify the uri and query parameters before the authorization redirect
// server.service.on('beforeAuthorizeRedirect', (authorizeRedirectUri, req) => {
// authorizeRedirectUri.url.searchParams.set('foo', 'bar');
// });
// Simulates a custom token revocation body
// server.service.on('beforeRevoke', (revokeResponse, req) => {
// revokeResponse.body = {
// result: 'revoked',
// };
// });
// Force the oidc service to provide an invalid_grant response on next call to the token endpoint
// server.service.on('beforeResponse', (tokenEndpointResponse, req) => {
// tokenEndpointResponse.body = {
// error: 'invalid_grant',
// };
// tokenEndpointResponse.statusCode = 400;
// });
server.service.on('beforeUserinfo', (userInfoResponse, req) => {
userInfoResponse.body = {
email: "[email protected]",
email_verified: true,
family_name: "Company",
given_name: "Indice",
name: "[email protected]",
preferred_username: "[email protected]",
sub: "johndoe",
};
//userInfoResponse.statusCode = 401;
});
}
async function StartServer(server) {
// Generate a new RSA key and add it to the keystore
await server.issuer.keys.generate('RS256');
// Start the server
await server.start(8080, 'localhost');
//console.log('Issuer URL:', server.issuer.url); // -> http://localhost:8080
}
async function StopServer() {
await server.stop();
};
Main();