Skip to content

feat: enable multiple auth methods #963

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 23 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
884f0a6
feat(auth): refactor and improve existing auth methods
jescalada Feb 16, 2025
ce6023b
feat(auth): configure passport with all enabled auth methods
jescalada Feb 16, 2025
68fa115
test(auth): fix tests for multiple auth methods
jescalada Feb 16, 2025
0a74501
Merge branch 'oidc-implementation' into enable-multiple-auth-methods
jescalada Feb 21, 2025
627c0ea
fix(auth): refactor how auth strategies are loaded into API route mid…
jescalada Feb 21, 2025
db30bef
Merge branch 'layout-auth-decoupling' into enable-multiple-auth-methods
jescalada Mar 10, 2025
b58d3a8
fix(auth): fix OIDC login e2e test
jescalada Mar 10, 2025
291c179
fix(auth): fix linter issues
jescalada Mar 10, 2025
2f19f82
fix(auth): try to fix ESM issue on openid-client import
jescalada Mar 10, 2025
1397265
Merge branch 'main' into enable-multiple-auth-methods
jescalada Apr 2, 2025
0ddd27b
fix(auth): fix bug when calling createUser on admin creation
jescalada May 21, 2025
3484694
Merge remote-tracking branch 'origin/main' into enable-multiple-auth-…
jescalada May 21, 2025
e32408c
chore(auth): add sample oidc config
jescalada May 21, 2025
c83421d
fix: admin to dashboard rename issues
jescalada May 21, 2025
bab0061
fix: failing Cypress test
jescalada May 21, 2025
70dd346
test(auth): add proxyquire for mocking
jescalada May 21, 2025
71e7e52
test(auth): improve test coverage
jescalada May 21, 2025
678d932
test(auth): fix service close issue
jescalada May 21, 2025
ee8f2c1
test(auth): add extra tests and fix linter issues
jescalada May 21, 2025
e96e876
fix: replaced loading text with actual spinner and removed debug lines
jescalada May 21, 2025
fd962d2
feat: add snackbar for repo fetching errors
jescalada May 21, 2025
304a2ec
fix: revert react missing from PrivateRoute scope
jescalada May 21, 2025
ddc20bf
Merge remote-tracking branch 'origin/main' into enable-multiple-auth-…
jescalada May 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cypress/e2e/autoApproved.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import moment from 'moment';

describe('Auto-Approved Push Test', () => {
beforeEach(() => {
cy.login('admin', 'admin');

cy.intercept('GET', '/api/v1/push/123', {
statusCode: 200,
body: {
Expand Down Expand Up @@ -45,7 +47,7 @@ describe('Auto-Approved Push Test', () => {
});

it('should display auto-approved message and verify tooltip contains the expected timestamp', () => {
cy.visit('/admin/push/123');
cy.visit('/dashboard/push/123');

cy.wait('@getPush');

Expand Down
16 changes: 15 additions & 1 deletion cypress/e2e/login.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,29 @@ describe('Login page', () => {
cy.get('[data-test="login"]').should('exist');
});

it('should redirect to repo list on valid login', () => {
cy.intercept('GET', '**/api/auth/me').as('getUser');

cy.get('[data-test="username"]').type('admin');
cy.get('[data-test="password"]').type('admin');
cy.get('[data-test="login"]').click();

cy.wait('@getUser');

cy.url().should('include', '/dashboard/repo');
})

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', () => {
// Set intercept first, since redirect on click can be quick
cy.intercept('GET', '/api/auth/oidc').as('oidcRedirect');
cy.get('[data-test="oidc-login"]').click();
cy.url().should('include', '/oidc');
cy.wait('@oidcRedirect');
});
});
});
6 changes: 4 additions & 2 deletions cypress/e2e/repo.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe('Repo', () => {
beforeEach(() => {
cy.visit('/admin/repo');
cy.login('admin', 'admin');

cy.visit('/dashboard/repo');

// prevent failures on 404 request and uncaught promises
cy.on('uncaught:exception', () => false);
Expand All @@ -18,7 +20,7 @@ describe('Repo', () => {

cy
// find the entry for finos/test-repo
.get('a[href="/admin/repo/test-repo"]')
.get('a[href="/dashboard/repo/test-repo"]')
// take it's parent row
.closest('tr')
// find the nearby span containing Code we can click to open the tooltip
Expand Down
6 changes: 5 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
Cypress.Commands.add('login', (username, password) => {
cy.session([username, password], () => {
cy.visit('/login');
cy.intercept('GET', '**/api/auth/me').as('getUser');

cy.get('[data-test=username]').type(username);
cy.get('[data-test=password]').type(password);
cy.get('[data-test=login]').click();
cy.url().should('contain', '/admin/profile');

cy.wait('@getUser');
cy.url().should('include', '/dashboard/repo');
});
});
77 changes: 73 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"mocha": "^10.8.2",
"nyc": "^17.0.0",
"prettier": "^3.0.0",
"proxyquire": "^2.1.3",
"sinon": "^19.0.2",
"ts-mocha": "^11.1.0",
"ts-node": "^10.9.2",
Expand Down
11 changes: 11 additions & 0 deletions proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
"baseDN": "",
"searchBase": ""
}
},
{
"type": "openidconnect",
"enabled": false,
"oidcConfig": {
"issuer": "",
"clientID": "",
"clientSecret": "",
"callbackURL": "",
"scope": ""
}
}
],
"api": {
Expand Down
22 changes: 12 additions & 10 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,29 @@ export const getDatabase = () => {
throw Error('No database cofigured!');
};

// Gets the configured authentication method, defaults to local
export const getAuthentication = () => {
/**
* Get the list of enabled authentication methods
* @return {Array} List of enabled authentication methods
*/
export const getAuthMethods = () => {
if (_userSettings !== null && _userSettings.authentication) {
_authentication = _userSettings.authentication;
}
for (const ix in _authentication) {
if (!ix) continue;
const auth = _authentication[ix];
if (auth.enabled) {
return auth;
}

const enabledAuthMethods = _authentication.filter((auth) => auth.enabled);

if (enabledAuthMethods.length === 0) {
throw new Error("No authentication method enabled");
}

throw Error('No authentication cofigured!');
return enabledAuthMethods;
};

// Log configuration to console
export const logConfiguration = () => {
console.log(`authorisedList = ${JSON.stringify(getAuthorisedList())}`);
console.log(`data sink = ${JSON.stringify(getDatabase())}`);
console.log(`authentication = ${JSON.stringify(getAuthentication())}`);
console.log(`authentication = ${JSON.stringify(getAuthMethods())}`);
console.log(`rateLimit = ${JSON.stringify(getRateLimit())}`);
};

Expand Down
23 changes: 15 additions & 8 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { createBrowserHistory } from 'history';
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { AuthProvider } from './ui/auth/AuthProvider';

// core components
import Admin from './ui/layouts/Admin';
import Dashboard from './ui/layouts/Dashboard';
import Login from './ui/views/Login/Login';
import './ui/assets/css/material-dashboard-react.css';
import NotAuthorized from './ui/views/Extras/NotAuthorized';
import NotFound from './ui/views/Extras/NotFound';

const hist = createBrowserHistory();

ReactDOM.render(
<Router history={hist}>
<Routes>
<Route exact path='/admin/*' element={<Admin />} />
<Route exact path='/login' element={<Login />} />
<Route exact path='/' element={<Navigate from='/' to='/admin/repo' />} />
</Routes>
</Router>,
<AuthProvider>
<Router history={hist}>
<Routes>
<Route exact path='/dashboard/*' element={<Dashboard />} />
<Route exact path='/login' element={<Login />} />
<Route exact path='/not-authorized' element={<NotAuthorized />} />
<Route exact path='/' element={<Navigate from='/' to='/dashboard/repo' />} />
<Route path='*' element={<NotFound />} />
</Routes>
</Router>
</AuthProvider>,
document.getElementById('root'),
);
2 changes: 1 addition & 1 deletion src/proxy/processors/push-action/blockForAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const exec = async (req: any, action: Action) => {
'\n\n\n' +
`\x1B[32mGitProxy has received your push ✅\x1B[0m\n\n` +
'🔗 Shareable Link\n\n' +
`\x1B[34m${url}/admin/push/${action.id}\x1B[0m` +
`\x1B[34m${url}/dashboard/push/${action.id}\x1B[0m` +
'\n\n\n';
step.setAsyncBlock(message);

Expand Down
Loading
Loading