Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions projects/keycloak-angular/src/lib/provide-keycloak.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ describe('provideKeycloak', () => {
expect(keycloak.didInitialize).toBeFalse();
});

it('should instantiate keycloak with a string URL config', () => {
const config = '/keycloak.json';

TestBed.configureTestingModule({
providers: [provideKeycloak({ config })]
});

const keycloak = TestBed.inject(Keycloak);

expect(keycloak).toBeDefined();
expect(keycloak.didInitialize).toBeFalse();
});

it('should instantiate keycloak and be able to initialize the instance later', () => {
const config: KeycloakConfig = {
url: 'kc-server-url',
Expand Down
42 changes: 23 additions & 19 deletions projects/keycloak-angular/src/lib/provide-keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import { KeycloakFeature } from './features/keycloak.feature';
*/
export type ProvideKeycloakOptions = {
/**
* Keycloak configuration, including the server URL, realm, and client ID.
* Keycloak configuration. Can be either a KeycloakConfig object with
* the server URL, realm, and client ID, or a string URL pointing to
* a keycloak.json configuration file (e.g., '/keycloak.json').
*/
config: KeycloakConfig;
config: KeycloakConfig | string;

/**
* Optional initialization options for the Keycloak instance.
Expand Down Expand Up @@ -82,7 +84,8 @@ const provideKeycloakInAppInitializer = (
* In such cases, the application must call `keycloak.init()` explicitly.
*
* @param options - Configuration object for Keycloak:
* - `config`: The Keycloak configuration, including the server URL, realm, and client ID.
* - `config`: The Keycloak configuration. Can be either a KeycloakConfig object with
* url, realm, and clientId, or a string URL pointing to a keycloak.json file.
* - `initOptions` (Optional): Initialization options for the Keycloak instance.
* - `providers` (Optional): Additional Angular providers to include.
* - `features` (Optional): Keycloak Angular features to configure during initialization.
Expand All @@ -91,23 +94,24 @@ const provideKeycloakInAppInitializer = (
*
* @example
* ```ts
* import { provideKeycloak } from './keycloak.providers';
* import { bootstrapApplication } from '@angular/platform-browser';
* import { AppComponent } from './app/app.component';
* // Using a KeycloakConfig object
* provideKeycloak({
* config: {
* url: 'https://auth-server.example.com',
* realm: 'my-realm',
* clientId: 'my-client',
* },
* initOptions: {
* onLoad: 'login-required',
* },
* });
*
* bootstrapApplication(AppComponent, {
* providers: [
* provideKeycloak({
* config: {
* url: 'https://auth-server.example.com',
* realm: 'my-realm',
* clientId: 'my-client',
* },
* initOptions: {
* onLoad: 'login-required',
* },
* }),
* ],
* // Using a string URL to a keycloak.json file
* provideKeycloak({
* config: '/keycloak.json',
* initOptions: {
* onLoad: 'login-required',
* },
* });
* ```
*/
Expand Down