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 // This example commands.js shows you how to
// create various custom commands and overwrite // create various custom commands and overwrite
@ -26,9 +28,11 @@
Cypress.Commands.add('signInToAdmin', (selector, ...args) => { Cypress.Commands.add('signInToAdmin', (selector, ...args) => {
cy.visit('/admin'); cy.visit('/admin');
// cy.get('#username').type('ciadmin1'); if (AUTH_WITH_KEYCLOAK) {
// cy.get('#password').type('ciadmin1'); cy.get('#username').type('ciadmin1');
// cy.get('#kc-login').click(); cy.get('#password').type('ciadmin1');
cy.get('#kc-login').click();
}
}); });
Cypress.Commands.add('getBySel', (selector, ...args) => { 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 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); UserService.initKeycloak(doRender);
// doRender();
// If you want to start measuring performance in your app, pass a function // If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log)) // to log results (for example: reportWebVitals(console.log))

View File

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