Skip to content

Commit

Permalink
FORMS-5164 - BC Services Card Demo
Browse files Browse the repository at this point in the history
add bc services card as IDP
add verified person as IDP

Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed Oct 24, 2024
1 parent 5f754dc commit f57f643
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/chefs_local/local.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"public": {
"limitApiKey": "120",
"limitFrontend": "500",
"windowMs": "60000",
"windowMs": "60000"
}
},
"encryption": {
Expand Down
4 changes: 2 additions & 2 deletions app/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"apiPath": "FRONTEND_APIPATH",
"basePath": "VITE_FRONTEND_BASEPATH",
"oidc": {
"clientId": "OIDC_CLIENTID",
"clientId": "BCSC_DEMO_OIDC_CLIENTID",
"realm": "OIDC_REALM",
"serverUrl": "OIDC_SERVERURL",
"logoutUrl": "OIDC_LOGOUTURL"
Expand All @@ -48,7 +48,7 @@
"serverUrl": "OIDC_SERVERURL",
"jwksUri": "OIDC_JWKSURI",
"issuer": "OIDC_ISSUER",
"audience": "OIDC_CLIENTID",
"audience": "BCSC_DEMO_OIDC_CLIENTID",
"maxTokenAge": "OIDC_MAXTOKENAGE"
},
"logFile": "SERVER_LOGFILE",
Expand Down
5 changes: 3 additions & 2 deletions app/frontend/src/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ export const useAuthStore = defineStore('auth', {
// Determine idpHint based on input or form
if (idpHint && typeof idpHint === 'string') options.idpHint = idpHint;

const idpStore = useIdpStore();
if (options.idpHint) {
// Redirect to Keycloak if idpHint is available
window.location.replace(this.createLoginUrl(options));
const loginOptions = idpStore.getLoginOptions(options.idpHint);
window.location.replace(this.createLoginUrl(options) + loginOptions);
} else {
// Navigate to internal login page if no idpHint specified
const router = getRouter();
const idpStore = useIdpStore();
router.replace({
name: 'Login',
query: { idpHint: idpStore.loginIdpHints },
Expand Down
12 changes: 12 additions & 0 deletions app/frontend/src/store/identityProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ export const useIdpStore = defineStore('idps', {
}
return false;
},
getLoginOptions(hint) {
let result = ''; // return empty string so no check needed to add to existing string.
if (hint && this.providers) {
const idp = this.providers.find((x) => x.idp === hint);
if (idp) {
if (idp.extra?.loginOptions) {
result = idp.extra?.loginOptions;
}
}
}
return result;
},
hasFormAccessSettings(code, accessSettingsType) {
let result = false;
if (code && accessSettingsType && this.providers) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/components/idpService.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class IdpService {
throw new Error(`Value in token mapped to '${key}' cannot be converted from JSON.`);
}
break;
case 'raw':
tokenValue = k_fn[0]; // just take the key as value, no conversion, no lookup
break;
default:
throw new Error(`Value in token mapped to '${key}' specified unknown parsing routine: ${fn}.`);
}
Expand Down
60 changes: 60 additions & 0 deletions app/src/db/migrations/20241024170248_99_idp_bcsc_dc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { APP_PERMISSIONS, Roles } = require('../../forms/common/constants');

const CREATED_BY = 'migration-099';
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return Promise.resolve().then(() => {
return knex('identity_provider').insert([
{
createdBy: CREATED_BY,
code: 'bcservicescard',
display: 'BC Services Card',
active: true,
idp: 'chefs-localhost-bcservice-5754',
primary: false,
login: true,
permissions: [APP_PERMISSIONS.VIEWS_USER_SUBMISSIONS],
roles: [Roles.FORM_SUBMITTER],
tokenmap: {
idpUserId: 'sub',
keycloakId: 'sub',
idp: 'identity_provider',
username: 'anonymous::raw',
fullName: 'anonymous::raw',
},
},
{
createdBy: CREATED_BY,
code: 'verified-person-bcpc-dev',
display: 'Verified Person',
active: true,
idp: 'digitalcredential',
primary: false,
login: true,
permissions: [],
roles: [Roles.FORM_SUBMITTER],
tokenmap: {
idpUserId: 'verified-person-bcpc-dev::raw',
keycloakId: 'verified-person-bcpc-dev::raw',
idp: 'identity_provider',
username: 'anonymous::raw',
fullName: 'anonymous::raw',
// firstName: 'given_names',
// lastName: 'family_name',
},
extra: {
loginOptions: '&pres_req_conf_id=verified-person-bcpc-dev',
},
},
]);
});
};

exports.down = function (knex) {
return Promise.resolve().then(() => {
return knex('identity_provider').where('createdBy', CREATED_BY).del();
});
};
2 changes: 2 additions & 0 deletions openshift/app.dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ objects:
name: "${APP_NAME}-oidc-config"
- configMapRef:
name: "${APP_NAME}-custombcaddressformiocomponent-config"
- configMapRef:
name: "${APP_NAME}-bcsc-demo-oidc-config"
restartPolicy: Always
terminationGracePeriodSeconds: 30
volumes:
Expand Down

0 comments on commit f57f643

Please sign in to comment.