-
Notifications
You must be signed in to change notification settings - Fork 155
feat: Preliminary OIDC implementation #906
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d3d04a0
feat(auth): add OIDC login button to login page
jescalada d157d96
feat(auth): add OIDC strategy to passport
jescalada 1c19264
feat(auth): add OIDC database handler and endpoint
jescalada 96edf6a
fix(auth): fix null password error on OIDC login
jescalada ddcacee
fix(backend): serve static files only in production
jescalada 5c93210
test(auth): add basic E2E test for OIDC
jescalada c61506a
Merge branch 'main' into oidc-implementation
JamieSlome 8d0453f
chore(auth): remove unnecessary changes
jescalada 49a09b3
Merge branch 'oidc-implementation' of https://github.com/jescalada/gi…
jescalada 52e33d9
feat(auth): refactor to use openid-client instead of passport-openidc…
jescalada 4f71e77
chore(auth): fix lint warnings
jescalada 0a0656d
fix(auth): attempt to fix CI ERR_REQUIRE_ESM
jescalada a096252
Merge branch 'main' into oidc-implementation
jescalada 712938b
fix(auth): fix bug with default admin account
jescalada 8017b10
Merge branch 'main' into oidc-implementation
JamieSlome 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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| const { defineConfig } = require('cypress') | ||
| const { defineConfig } = require('cypress'); | ||
|
|
||
| module.exports = defineConfig({ | ||
| e2e: { | ||
| baseUrl: process.env.CYPRESS_BASE_URL ||'http://localhost:3000', | ||
| baseUrl: process.env.CYPRESS_BASE_URL || 'http://localhost:3000', | ||
| chromeWebSecurity: false, // Required for OIDC testing | ||
| }, | ||
| }) | ||
| }); |
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,19 +1,33 @@ | ||
| describe("Display finos UI",()=>{ | ||
|
|
||
| beforeEach(() =>{ | ||
| cy.visit('/login') | ||
| }) | ||
| it('shoud find git proxy logo',() =>{ | ||
| cy.get('[data-test="git-proxy-logo"]').should('exist') | ||
| }) | ||
| it('shoud find username',() =>{ | ||
| cy.get('[data-test="username"]').should('exist') | ||
| }) | ||
| describe('Login page', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/login'); | ||
| }); | ||
|
|
||
| it('shoud find passsword',() =>{ | ||
| cy.get('[data-test="password"]').should('exist') | ||
| }) | ||
| it('shoud find login button',() =>{ | ||
| cy.get('[data-test="login"]').should('exist') | ||
| }) | ||
| }) | ||
| it('should have git proxy logo', () => { | ||
| cy.get('[data-test="git-proxy-logo"]').should('exist'); | ||
| }); | ||
|
|
||
| it('should have username input', () => { | ||
| cy.get('[data-test="username"]').should('exist'); | ||
| }); | ||
|
|
||
| it('should have passsword input', () => { | ||
| cy.get('[data-test="password"]').should('exist'); | ||
| }); | ||
|
|
||
| it('should have login button', () => { | ||
| cy.get('[data-test="login"]').should('exist'); | ||
| }); | ||
|
|
||
| describe('OIDC login button', () => { | ||
| it('should exist', () => { | ||
| cy.get('[data-test="oidc-login"]').should('exist'); | ||
| }); | ||
|
|
||
| // Validates that OIDC is configured correctly | ||
| it('should redirect to /oidc', () => { | ||
| cy.get('[data-test="oidc-login"]').click(); | ||
| cy.url().should('include', '/oidc'); | ||
| }); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
jescalada marked this conversation as resolved.
Show resolved
Hide resolved
|
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,91 @@ | ||
| const configure = async () => { | ||
| const passport = require('passport'); | ||
| const { Strategy: OIDCStrategy } = require('passport-openidconnect'); | ||
| const db = require('../../db'); | ||
|
|
||
| const config = require('../../config').getAuthentication(); | ||
| const oidcConfig = config.oidcConfig; | ||
|
|
||
| passport.use( | ||
| new OIDCStrategy(oidcConfig, async function verify(issuer, profile, cb) { | ||
| try { | ||
| const user = await db.findUserByOIDC(profile.id); | ||
|
|
||
| if (!user) { | ||
| const email = safelyExtractEmail(profile); | ||
| if (!email) { | ||
| return cb(new Error('No email found in OIDC profile')); | ||
| } | ||
|
|
||
| const username = getUsername(email); | ||
| const newUser = { | ||
| username: username, | ||
| email: email, | ||
| oidcId: profile.id, | ||
| }; | ||
|
|
||
| await db.createUser( | ||
| newUser.username, | ||
| null, | ||
| newUser.email, | ||
| 'Edit me', | ||
| false, | ||
| newUser.oidcId, | ||
| ); | ||
|
|
||
| return cb(null, newUser); | ||
| } | ||
| return cb(null, user); | ||
| } catch (err) { | ||
| return cb(err); | ||
| } | ||
| }), | ||
| ); | ||
|
|
||
| passport.serializeUser((user, cb) => { | ||
| cb(null, user.oidcId || user.username); | ||
| }); | ||
|
|
||
| passport.deserializeUser(async (id, cb) => { | ||
| try { | ||
| const user = (await db.findUserByOIDC(id)) || (await db.findUser(id)); | ||
| cb(null, user); | ||
| } catch (err) { | ||
| cb(err); | ||
| } | ||
| }); | ||
|
|
||
| passport.type = 'openidconnect'; | ||
| return passport; | ||
| }; | ||
|
|
||
| module.exports.configure = configure; | ||
|
|
||
| /** | ||
| * Extracts email from OIDC profile. | ||
| * This function is necessary because OIDC providers have different ways of storing emails. | ||
| * @param {object} profile the profile object from OIDC provider | ||
| * @return {string | null} the email address | ||
| */ | ||
| const safelyExtractEmail = (profile) => { | ||
| if (profile.emails && profile.emails.length > 0) { | ||
| return profile.emails[0].value; | ||
| } | ||
|
|
||
| if (profile.email) { | ||
| return profile.email; | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| /** | ||
| * Generates a username from email address. | ||
| * This helps differentiate users within the specific OIDC provider. | ||
| * Note: This is incompatible with multiple providers. Ideally, users are identified by | ||
| * OIDC ID (requires refactoring the database). | ||
| * @param {string} email the email address | ||
| * @return {string} the username | ||
| */ | ||
| const getUsername = (email) => { | ||
| return email ? email.split('@')[0] : ''; | ||
| }; |
Oops, something went wrong.
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.