-
Notifications
You must be signed in to change notification settings - Fork 7
feat(IPROD-189-3): used Keycloak to perform /login action to do OAuth 2.0 authorization code flow #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
geka-evk
wants to merge
16
commits into
main
Choose a base branch
from
IPROD-189-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(IPROD-189-3): used Keycloak to perform /login action to do OAuth 2.0 authorization code flow #83
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
35f74bf
feat/IPROD-189-3 used Keycloak to perform /login action to do OAuth 2…
geka-evk 2f12d6f
IPROD-189-3 fixed some failed tests
geka-evk ea1ad5d
IPROD-189-3 fixed some failed tests
geka-evk 0b7f917
IPROD-189-3: updated cachix/install-nix-action version to v22
geka-evk b251578
IPROD-189-3: updated README
geka-evk 912f055
IPROD-189-3: updated README
geka-evk 22d57fa
IPROD-189-3: in case of 403 error, redirect to /login
geka-evk d4a54e5
IPROD-189-3: redirected use back (not only to root) after login
geka-evk 62c520c
IPROD-189-3: redirected use back (not only to root) after login
geka-evk b801d04
IPROD-189-3: on DFSP onboard request use id, not name
geka-evk cfe131a
IPROD-189-9 made auth disabled by default; fixed redirect url logic (…
geka-evk 547bfc5
IPROD-189-9 removed snapshot version
geka-evk b8cb754
IPROD-189-9 used sessionStorage for redirect after login
geka-evk 468722e
IPROD-189-3 Renamed OIDC_CLIENT_ID/SECRET env vars
geka-evk 2e7e40f
Apply suggestions from code review
geka-evk 72709db
Update README.md
geka-evk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ jobs: | |
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/[email protected] | ||
| - uses: cachix/install-nix-action@v13 | ||
| - uses: cachix/install-nix-action@v22 | ||
| with: | ||
| nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17.tar.gz | ||
| - name: Install dependencies in environment | ||
|
|
@@ -25,7 +25,7 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| - uses: cachix/install-nix-action@v13 | ||
| - uses: cachix/install-nix-action@v22 | ||
| with: | ||
| nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/8e4fe32876ca15e3d5eb3ecd3ca0b224417f5f17.tar.gz | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
| const { | ||
| API_BASE_URL, | ||
| AUTH_ENABLED, | ||
| UI_OIDC_LOGIN_REDIRECT_URL, | ||
| OIDC_TOKEN_PROVIDER_URL, | ||
| OIDC_CLIENT_ID, | ||
| OIDC_CLIENT_SECRET, | ||
| MCM_COOKIE_NAME = 'MCM_SESSION', | ||
| HTTP_PORT = 8080, | ||
| } = process.env; | ||
| // validate required env vars | ||
|
|
||
| module.exports = { | ||
| API_BASE_URL, | ||
| AUTH_ENABLED, | ||
| UI_OIDC_LOGIN_REDIRECT_URL, | ||
| OIDC_TOKEN_PROVIDER_URL, | ||
| OIDC_CLIENT_ID, | ||
| OIDC_CLIENT_SECRET, | ||
| MCM_COOKIE_NAME, | ||
| HTTP_PORT, | ||
| }; |
This file contains hidden or 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,34 @@ | ||
| const querystring = require('querystring'); | ||
| const axios = require('axios').default; | ||
| const config = require('./config'); | ||
|
|
||
| const makeOidcPayload = (code) => querystring.stringify({ | ||
| code, | ||
| client_id: config.OIDC_CLIENT_ID, | ||
| client_secret: config.OIDC_CLIENT_SECRET, | ||
| grant_type: 'authorization_code', | ||
| }); | ||
|
|
||
| const requestOptions = { | ||
| headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
| }; | ||
|
|
||
| const exchangeAuthCodeForToken = async (code) => { | ||
| const url = config.OIDC_TOKEN_PROVIDER_URL; | ||
| const payload = makeOidcPayload(code); | ||
|
|
||
| return axios.post(url, payload, requestOptions) | ||
| .then((response) => { | ||
| const { access_token, expires_in } = response.data; // expires_in in sec | ||
| return { access_token, expires_in }; | ||
| }) | ||
| .catch((err) => { | ||
| const error = `exchange authCode error: ${err.message} - ${JSON.stringify(err.response && err.response.data)}`; | ||
| console.error(error, code); | ||
| return { error }; | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| exchangeAuthCodeForToken, | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,20 +1,44 @@ | ||
| const express = require('express'); | ||
| const path = require('path'); | ||
| const express = require('express'); | ||
|
|
||
| const { exchangeAuthCodeForToken } = require('./httpRequest'); | ||
| const { | ||
| HTTP_PORT, | ||
| API_BASE_URL, | ||
| AUTH_ENABLED, | ||
| UI_OIDC_LOGIN_REDIRECT_URL, | ||
| OIDC_CLIENT_ID, | ||
| MCM_COOKIE_NAME | ||
| } = require('./config'); | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.use(express.static(path.join(__dirname, 'build'))); | ||
|
|
||
| app.get('/config', function (req, res) { | ||
| let config = { | ||
| API_BASE_URL: process.env.API_BASE_URL, | ||
| AUTH_ENABLED: process.env.AUTH_ENABLED, | ||
| app.get('/config', (req, res) => { | ||
| const config = { | ||
| API_BASE_URL, | ||
| AUTH_ENABLED, | ||
| UI_OIDC_LOGIN_REDIRECT_URL, | ||
| OIDC_CLIENT_ID, | ||
| MCM_COOKIE_NAME, | ||
| }; | ||
| console.log('connection-manager-ui server: /config called, returning: ', config); | ||
| res.send(config); | ||
| }); | ||
|
|
||
| app.get('/*', function (req, res) { | ||
| app.get('/oidc-token', async (req, res) => { | ||
| const { code } = req.query; | ||
| const response = await exchangeAuthCodeForToken(code); | ||
| console.log('oidc response:', response); | ||
|
|
||
| res | ||
| .status(response.access_token ? 200 : 401) | ||
| .json(response); | ||
| }); | ||
|
|
||
| app.get('/*', (req, res) => { | ||
| res.sendFile(path.join(__dirname, 'build', 'index.html')); | ||
| }); | ||
|
|
||
| app.listen(8080); | ||
| app.listen(HTTP_PORT, () => { console.log(`Server is running on port ${HTTP_PORT}...`); }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.