-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds oauth mock * forgot to commit this
- Loading branch information
1 parent
2138213
commit 01a96a3
Showing
5 changed files
with
268 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### What is this? | ||
|
||
This is a mock OAuth server for testing purposes. It allows you to run pyroscope with oauth enabled locally by mimicking gitlab oauth server. | ||
|
||
|
||
### Usage | ||
|
||
To run the mock server, run the following command: | ||
```shell | ||
node ./scripts/oauth-mock/oauth-mock.js | ||
``` | ||
|
||
To run pyroscope with the right config run: | ||
```shell | ||
make build | ||
bin/pyroscope server -config scripts/oauth-mock/pyroscope-config.yml | ||
``` | ||
|
||
Then go to http://localhost:4040/ and pyroscope should send you to log in via GitLab (which is really just our mock in this case). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
async function main() { | ||
// eslint-disable-next-line global-require | ||
const { OAuth2Server } = require('oauth2-mock-server'); | ||
|
||
const server = new OAuth2Server(undefined, undefined, { | ||
endpoints: { | ||
wellKnownDocument: '/.well-known/openid-configuration', | ||
token: '/token', | ||
jwks: '/jwks', | ||
authorize: '/authorize', | ||
userinfo: '/user', | ||
revoke: '/revoke', | ||
endSession: '/endSession', | ||
introspect: '/introspect', | ||
}, | ||
}); | ||
|
||
// hack to add /groups support to the mock server | ||
server.service.requestHandler.get('/groups', (req, res) => { | ||
res.status(200).json([{ path: 'allowed-group-example' }]); | ||
}); | ||
|
||
server.service.once('beforeUserinfo', (userInfoResponse, req) => { | ||
console.log('beforeUserinfo'); | ||
userInfoResponse.body = { | ||
id: 1245, | ||
email: 'test@test.com', | ||
username: 'testuser', | ||
avatarurl: | ||
'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50', | ||
}; | ||
}); | ||
|
||
// Generate a new RSA key and add it to the keystore | ||
await server.issuer.keys.generate('RS256'); | ||
|
||
// Start the server | ||
await server.start(18080, 'localhost'); | ||
console.log('Issuer URL:', server.issuer.url); // -> http://localhost:8080 | ||
|
||
// Do some work with the server | ||
// ... | ||
|
||
// Stop the server | ||
// return await server.stop(); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
auth: | ||
gitlab: | ||
enabled: true | ||
api-url: http://localhost:18080 | ||
auth-url: http://localhost:18080/authorize | ||
token-url: http://localhost:18080/token | ||
client-id: 42fe36a3c42334416f36f71049aa5efe | ||
client-secret: 16f36f71049aa5efe42fe36a3c423344 | ||
# allowed-groups: | ||
# - allowed-group-example | ||
storage-path: tmp/oauth-mock-storage | ||
log-level: debug |
Oops, something went wrong.