github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/scripts/oauth-mock/oauth-mock.js (about) 1 async function main() { 2 // eslint-disable-next-line global-require 3 const { OAuth2Server } = require('oauth2-mock-server'); 4 5 const server = new OAuth2Server(undefined, undefined, { 6 endpoints: { 7 wellKnownDocument: '/.well-known/openid-configuration', 8 token: '/token', 9 jwks: '/jwks', 10 authorize: '/authorize', 11 userinfo: '/user', 12 revoke: '/revoke', 13 endSession: '/endSession', 14 introspect: '/introspect', 15 }, 16 }); 17 18 // hack to add /groups support to the mock server 19 server.service.requestHandler.get('/groups', (req, res) => { 20 res.status(200).json([{ path: 'allowed-group-example' }]); 21 }); 22 23 server.service.addListener('beforeUserinfo', (userInfoResponse, req) => { 24 userInfoResponse.body = { 25 id: 1245, 26 email: 'test@test.com', 27 username: 'testuser', 28 avatarurl: 29 'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50', 30 }; 31 }); 32 33 // Generate a new RSA key and add it to the keystore 34 await server.issuer.keys.generate('RS256'); 35 36 // Start the server 37 await server.start(18080, '0.0.0.0'); 38 console.log('Issuer URL:', server.issuer.url); // -> http://localhost:8080 39 40 // Do some work with the server 41 // ... 42 43 // Stop the server 44 // return await server.stop(); 45 } 46 47 main();