46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { environment } from '@vegasco-web/environments/environment';
|
|
import {
|
|
AutoRefreshTokenService,
|
|
createInterceptorCondition,
|
|
INCLUDE_BEARER_TOKEN_INTERCEPTOR_CONFIG,
|
|
IncludeBearerTokenCondition,
|
|
provideKeycloak,
|
|
UserActivityService,
|
|
withAutoRefreshToken
|
|
} from 'keycloak-angular';
|
|
|
|
const serverHostBearerInterceptorCondition = createInterceptorCondition<IncludeBearerTokenCondition>({
|
|
// The API is consumed through a proxy running on the same origin as the application.
|
|
// This means that the interceptor should include the bearer token for requests to the same origin
|
|
// which includes requests starting to / which implicitly sends the request to the same origin.
|
|
urlPattern: new RegExp(`^(${window.origin}|/)`)
|
|
});
|
|
|
|
export const provideKeycloakAngular = () =>
|
|
provideKeycloak({
|
|
config: {
|
|
url: environment.keycloak.host,
|
|
realm: environment.keycloak.realm,
|
|
clientId: environment.keycloak.clientId,
|
|
},
|
|
initOptions: {
|
|
onLoad: 'login-required',
|
|
silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html',
|
|
redirectUri: window.location.origin + '/',
|
|
checkLoginIframe: false,
|
|
},
|
|
features: [
|
|
withAutoRefreshToken({
|
|
onInactivityTimeout: 'login',
|
|
})
|
|
],
|
|
providers: [
|
|
AutoRefreshTokenService,
|
|
UserActivityService,
|
|
{
|
|
provide: INCLUDE_BEARER_TOKEN_INTERCEPTOR_CONFIG,
|
|
useValue: [serverHostBearerInterceptorCondition]
|
|
}
|
|
]
|
|
});
|