diff --git a/lib/keycloak.d.ts b/lib/keycloak.d.ts index 9f5e07c..b2e8e49 100644 --- a/lib/keycloak.d.ts +++ b/lib/keycloak.d.ts @@ -228,6 +228,13 @@ export interface KeycloakInitOptions { * HTTP method for calling the end_session endpoint. Defaults to 'GET'. */ logoutMethod?: 'GET' | 'POST'; + + /** + * Configures url parameters to forward to Keycloak server. + * These are specified as an object with key-value pairs. + * Note that the keys need to be enabled in the Keycloak server in the 'Forwarded parameters' section. + */ + forwardParameters?: { [key: string]: string }; } export interface KeycloakLoginOptions { @@ -295,6 +302,13 @@ export interface KeycloakLoginOptions { */ locale?: string; + /** + * Configures url parameters to forward to Keycloak server. + * These are specified as an object with key-value pairs. + * Note that the keys need to be enabled in the Keycloak server in the 'Forwarded parameters' section. + */ + forwardParameters?: { [key: string]: string }; + /** * Specifies arguments that are passed to the Cordova in-app-browser (if applicable). * Options 'hidden' and 'location' are not affected by these arguments. diff --git a/lib/keycloak.js b/lib/keycloak.js index c59e5f7..66c7cd6 100755 --- a/lib/keycloak.js +++ b/lib/keycloak.js @@ -80,6 +80,8 @@ export default class Keycloak { /** @type {KeycloakPkceMethod} */ pkceMethod = 'S256'; enableLogging = false; + /** @type {{ [key: string]: string }=} */ + forwardParameters; /** @type {'GET' | 'POST'} */ logoutMethod = 'GET'; /** @type {string=} */ @@ -268,6 +270,10 @@ export default class Keycloak { this.scope = initOptions.scope; } + if (initOptions.forwardParameters) { + this.forwardParameters = initOptions.forwardParameters; + } + if (typeof initOptions.messageReceiveTimeout === 'number' && initOptions.messageReceiveTimeout > 0) { this.messageReceiveTimeout = initOptions.messageReceiveTimeout; } @@ -1268,6 +1274,13 @@ export default class Keycloak { params.append('acr_values', options.acrValues); } + if (options?.forwardParameters) { + const forwardParameters = options.forwardParameters; + Object.keys(forwardParameters).forEach(function (key) { + params.append(key, forwardParameters[key]); + }); + } + if (this.pkceMethod) { try { const codeVerifier = generateCodeVerifier(96);