added a config to turn keycloak on and off w/ burnettk

This commit is contained in:
jasquat 2022-07-11 14:20:58 -04:00
parent d44ffe8c5b
commit 0ed60ab6e7
4 changed files with 32 additions and 21 deletions

View File

@ -1,3 +1,5 @@
import { AUTH_WITH_KEYCLOAK } from '../../src/config';
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
@ -26,9 +28,11 @@
Cypress.Commands.add('signInToAdmin', (selector, ...args) => {
cy.visit('/admin');
// cy.get('#username').type('ciadmin1');
// cy.get('#password').type('ciadmin1');
// cy.get('#kc-login').click();
if (AUTH_WITH_KEYCLOAK) {
cy.get('#username').type('ciadmin1');
cy.get('#password').type('ciadmin1');
cy.get('#kc-login').click();
}
});
Cypress.Commands.add('getBySel', (selector, ...args) => {

View File

@ -29,3 +29,5 @@ export const PROCESS_STATUSES = [
];
export const DATE_FORMAT = 'yyyy-MM-dd HH:mm:ss';
export const AUTH_WITH_KEYCLOAK = true;

View File

@ -20,7 +20,6 @@ const doRender = () => {
};
UserService.initKeycloak(doRender);
// doRender();
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))

View File

@ -1,4 +1,5 @@
import Keycloak from 'keycloak-js';
import { AUTH_WITH_KEYCLOAK } from '../config';
const keycloakClient = new Keycloak('/keycloak.json');
@ -15,8 +16,11 @@ const updateToken = (successCallback: any) =>
const getUsername = () => keycloakClient.tokenParsed?.preferred_username;
const hasRole = (_roles: string[]) => {
// roles.some((role: string) => keycloakClient.hasRealmRole(role));
const hasRole = (roles: string[]) => {
if (AUTH_WITH_KEYCLOAK) {
return roles.some((role: string) => keycloakClient.hasRealmRole(role));
}
return true;
};
@ -26,21 +30,23 @@ const hasRole = (_roles: string[]) => {
* @param onAuthenticatedCallback
*/
const initKeycloak = (onAuthenticatedCallback: any) => {
// FIXME actually auth
if (AUTH_WITH_KEYCLOAK) {
keycloakClient
.init({
onLoad: 'check-sso',
silentCheckSsoRedirectUri: `${window.location.origin}/silent-check-sso.html`,
pkceMethod: 'S256',
})
.then((authenticated: any) => {
if (!authenticated) {
doLogin();
}
onAuthenticatedCallback();
// keycloakClient
// .init({
// onLoad: 'check-sso',
// silentCheckSsoRedirectUri: `${window.location.origin}/silent-check-sso.html`,
// pkceMethod: 'S256',
// })
// .then((authenticated: any) => {
// if (!authenticated) {
// doLogin();
// }
// onAuthenticatedCallback();
// })
// .catch(console.error);
})
.catch(console.error);
} else {
onAuthenticatedCallback();
}
};
const UserService = {