2023-05-03 11:27:27 +00:00
|
|
|
import Keycloak from "keycloak-js";
|
|
|
|
|
|
|
|
import environment from "./environment";
|
|
|
|
|
|
|
|
export const keycloak = new Keycloak({
|
|
|
|
url: environment.authServerUrl,
|
|
|
|
realm: environment.loginRealm,
|
2023-06-13 16:29:37 +00:00
|
|
|
clientId: environment.clientId,
|
2023-05-03 11:27:27 +00:00
|
|
|
});
|
2023-05-10 06:20:49 +00:00
|
|
|
|
|
|
|
export async function initKeycloak() {
|
|
|
|
const authenticated = await keycloak.init({
|
|
|
|
onLoad: "check-sso",
|
|
|
|
pkceMethod: "S256",
|
|
|
|
});
|
|
|
|
|
|
|
|
// Force the user to login if not authenticated.
|
|
|
|
if (!authenticated) {
|
|
|
|
await keycloak.login();
|
|
|
|
}
|
|
|
|
}
|