Skip to content

Commit

Permalink
Merge branch 'update-modules' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Sheriff committed Nov 6, 2024
2 parents 703750d + 91838a0 commit 86203ef
Show file tree
Hide file tree
Showing 9 changed files with 677 additions and 544 deletions.
6 changes: 6 additions & 0 deletions app/api/definitions/paths/authn-paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ paths:
required: true
schema:
type: string
- name: iss
in: query
description: |
iss provided by the identity server.
schema:
type: string
- name: state
in: query
description: |
Expand Down
3 changes: 2 additions & 1 deletion app/lib/authn-bearer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function verifyClientCredentialsToken(token, decodedHeader, done) {
// Make sure the client is allowed to access the REST API
// Okta returns the client id in payload.cid
// Keycloak returns the client id in payload.clientId
clientId = payload.cid || payload.clientId;
// Newer versions of keycloak appear to return the client id in payload.client_id
clientId = payload.cid || payload.clientId || payload.client_id;
const clients = config.serviceAuthn.oidcClientCredentials.clients;
const client = clients.find(c => c.clientId === clientId);
if (!client) {
Expand Down
1 change: 1 addition & 0 deletions app/tests/authn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Note that each test spec is run as a separate mocha job. This is because each sp
These tests require a keycloak server to be running. The server can be started on Docker with the command:

```shell
docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin --name keycloak -d quay.io/keycloak/keycloak:26.0.1 start-dev
docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin --name keycloak -d jboss/keycloak
```

Expand Down
2 changes: 1 addition & 1 deletion app/tests/authn/oidc-authn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('OIDC User Authentication', function () {
before(async function() {
// Configure the test to use OIDC authentication
process.env.AUTHN_MECHANISM = 'oidc';
process.env.AUTHN_OIDC_ISSUER_URL = `http://${ oidcHost }/auth/realms/${ oidcRealm }/.well-known/openid-configuration`;
process.env.AUTHN_OIDC_ISSUER_URL = `http://${ oidcHost }/realms/${ oidcRealm }/.well-known/openid-configuration`;
process.env.AUTHN_OIDC_CLIENT_ID = oidcClientId;

config.reloadConfig();
Expand Down
2 changes: 1 addition & 1 deletion app/tests/authn/oidc-client-credentials-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const oidcServiceClientSecret = '774ca536-b281-4783-bfed-cc362c39405b';
const localServerHost = 'localhost';
const localServerPort = 3000;
const localServerRedirectUrl = `http://${ localServerHost }:${localServerPort }/api/authn/oidc/*`;
const jwksUri = `http://${ oidcHost }/auth/realms/${ oidcRealm }/protocol/openid-connect/certs`;
const jwksUri = `http://${ oidcHost }/realms/${ oidcRealm }/protocol/openid-connect/certs`;

describe('Client Credentials Service Authentication', function () {
let app;
Expand Down
2 changes: 1 addition & 1 deletion app/tests/authn/oidc-register.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('OIDC User Account Registration', function () {
before(async function() {
// Configure the test to use OIDC authentication
process.env.AUTHN_MECHANISM = 'oidc';
process.env.AUTHN_OIDC_ISSUER_URL = `http://${ oidcHost }/auth/realms/${ oidcRealm }/.well-known/openid-configuration`;
process.env.AUTHN_OIDC_ISSUER_URL = `http://${ oidcHost }/realms/${ oidcRealm }/.well-known/openid-configuration`;
process.env.AUTHN_OIDC_CLIENT_ID = oidcClientId;

config.reloadConfig();
Expand Down
35 changes: 25 additions & 10 deletions app/tests/shared/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function deleteRealm(basePath, realmName, token) {
// Delete the realm if it exists
try {
await request
.delete(`${ basePath }/auth/admin/realms/${ realmName }`)
.delete(`${ basePath }/admin/realms/${ realmName }`)
.set('Authorization', `bearer ${token}`);
console.info(`Deleted existing realm ${ realmName }`);
}
Expand All @@ -34,7 +34,7 @@ async function createRealm(basePath, realmName, token) {

try {
await request
.post(`${ basePath }/auth/admin/realms`)
.post(`${ basePath }/admin/realms`)
.set('Authorization', `bearer ${token}`)
.send(realmData);
console.info(`Created realm ${ realmName }`);
Expand All @@ -61,7 +61,7 @@ async function createClient(options, token) {

try {
await request
.post(`${ options.basePath }/auth/admin/realms/${ options.realmName }/clients`)
.post(`${ options.basePath }/admin/realms/${ options.realmName }/clients`)
.set('Authorization', `bearer ${token}`)
.send(clientData);
console.info(`Created client ${ options.clientId }`);
Expand All @@ -75,7 +75,7 @@ async function createClient(options, token) {
async function getClient(options, token) {
try {
const res = await request
.get(`${ options.basePath }/auth/admin/realms/${ options.realmName }/clients?clientId=${ options.clientId }`)
.get(`${ options.basePath }/admin/realms/${ options.realmName }/clients?clientId=${ options.clientId }`)
.set('Authorization', `bearer ${token}`);

if (res.body.length === 1) {
Expand All @@ -94,7 +94,7 @@ async function getClient(options, token) {
async function createClientSecret(basePath, realmName, idOfClient, token) {
try {
const res = await request
.post(`${ basePath }/auth/admin/realms/${ realmName }/clients/${ idOfClient }/client-secret`)
.post(`${ basePath }/admin/realms/${ realmName }/clients/${ idOfClient }/client-secret`)
.set('Authorization', `bearer ${token}`);

return res.body;
Expand All @@ -108,7 +108,7 @@ async function createClientSecret(basePath, realmName, idOfClient, token) {
async function getClientSecret(basePath, realmName, idOfClient, token) {
try {
const res = await request
.get(`${ basePath }/auth/admin/realms/${ realmName }/clients/${ idOfClient }/client-secret`)
.get(`${ basePath }/admin/realms/${ realmName }/clients/${ idOfClient }/client-secret`)
.set('Authorization', `bearer ${token}`);

return res.body;
Expand All @@ -119,6 +119,19 @@ async function getClientSecret(basePath, realmName, idOfClient, token) {
}
}

async function getWellKnownConfiguration(basePath, realmName, token) {

Check failure on line 122 in app/tests/shared/keycloak.js

View workflow job for this annotation

GitHub Actions / static-checks

'getWellKnownConfiguration' is defined but never used
try {
const res = await request
.get(`${ basePath }/realms/${ realmName }/.well-known/openid-configuration`)
.set('Authorization', `bearer ${ token }`);
console.log(res);
}
catch (err) {
logger.error('Unable to get well known configuration');
throw err;
}
}

async function createUser(basePath, realmName, userOptions, token) {
const userData = {
email: userOptions.email,
Expand All @@ -137,8 +150,8 @@ async function createUser(basePath, realmName, userOptions, token) {

try {
await request
.post(`${ basePath }/auth/admin/realms/${ realmName }/users`)
.set('Authorization', `bearer ${token}`)
.post(`${ basePath }/admin/realms/${ realmName }/users`)
.set('Authorization', `bearer ${ token }`)
.send(userData);
console.info(`Added user '${ userOptions.username }' to the realm '${ realmName }' on the Keycloak server`);
}
Expand All @@ -151,7 +164,7 @@ async function createUser(basePath, realmName, userOptions, token) {
async function getAuthorizationToken(basePath) {
console.info(`Requesting authorization token from ${ basePath }`);
const res = await request
.post(`${ basePath }/auth/realms/master/protocol/openid-connect/token`)
.post(`${ basePath }/realms/master/protocol/openid-connect/token`)
.send(`client_id=${ adminClientId }`)
.send(`username=${ defaultAdminUsername }`)
.send(`password=${ defaultAdminPassword }`)
Expand Down Expand Up @@ -189,6 +202,8 @@ exports.addUsersToKeycloak = async function (serverOptions, users) {
// eslint-disable-next-line no-await-in-loop
await createUser(serverOptions.basePath, serverOptions.realmName, user, adminAccessToken);
}

// await getWellKnownConfiguration(serverOptions.basePath, serverOptions.realmName, adminAccessToken);
}

exports.addClientToKeycloak = async function(clientOptions) {
Expand All @@ -206,7 +221,7 @@ exports.addClientToKeycloak = async function(clientOptions) {
exports.getAccessTokenToClient = async function(clientOptions) {
console.info(`Requesting client access token for ${ clientOptions.clientId } from ${ clientOptions.basePath }`);
const res = await request
.post(`${ clientOptions.basePath }/auth/realms/${ clientOptions.realmName }/protocol/openid-connect/token`)
.post(`${ clientOptions.basePath }/realms/${ clientOptions.realmName }/protocol/openid-connect/token`)
.send(`client_id=${ clientOptions.clientId }`)
.send(`client_secret=${ clientOptions.clientSecret }`)
.send(`grant_type=client_credentials`);
Expand Down
Loading

0 comments on commit 86203ef

Please sign in to comment.