Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit d1355d6

Browse files
author
Mattia Panzeri
authored
Merge pull request #2 from react-keycloak/feature/LoginUrlExtraParam
feat: add new login url extra param
2 parents d34b05c + 3314005 commit d1355d6

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/client.ts

+33-17
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ export class KeycloakClient implements KeycloakInstance {
255255
const nonce = createUUID();
256256

257257
const redirectUri = this.adapter!.redirectUri(options);
258+
const {
259+
scope: scopeOption,
260+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
261+
redirectUri: redirectUriOption,
262+
prompt,
263+
action,
264+
maxAge,
265+
loginHint,
266+
idpHint,
267+
locale,
268+
...rest
269+
} = options ?? {};
258270

259271
let codeVerifier;
260272
let pkceChallenge;
@@ -272,18 +284,18 @@ export class KeycloakClient implements KeycloakInstance {
272284
};
273285

274286
let scope;
275-
if (options?.scope) {
276-
if (options.scope.indexOf('openid') !== -1) {
277-
scope = options.scope;
287+
if (scopeOption) {
288+
if (scopeOption.indexOf('openid') !== -1) {
289+
scope = scopeOption;
278290
} else {
279-
scope = 'openid ' + options.scope;
291+
scope = 'openid ' + scopeOption;
280292
}
281293
} else {
282294
scope = 'openid';
283295
}
284296

285297
const baseUrl =
286-
options && options.action === 'register'
298+
action === 'register'
287299
? this.endpoints!.register()
288300
: this.endpoints!.authorize();
289301

@@ -299,28 +311,28 @@ export class KeycloakClient implements KeycloakInstance {
299311
params.set('nonce', nonce);
300312
}
301313

302-
if (options?.prompt) {
303-
params.set('prompt', options.prompt);
314+
if (prompt) {
315+
params.set('prompt', prompt);
304316
}
305317

306-
if (options?.maxAge) {
307-
params.set('max_age', `${options.maxAge}`);
318+
if (maxAge) {
319+
params.set('max_age', `${maxAge}`);
308320
}
309321

310-
if (options?.loginHint) {
311-
params.set('login_hint', options.loginHint);
322+
if (loginHint) {
323+
params.set('login_hint', loginHint);
312324
}
313325

314-
if (options?.idpHint) {
315-
params.set('kc_idp_hint', options.idpHint);
326+
if (idpHint) {
327+
params.set('kc_idp_hint', idpHint);
316328
}
317329

318-
if (options?.action && options?.action !== 'register') {
319-
params.set('kc_action', options.action);
330+
if (action && action !== 'register') {
331+
params.set('kc_action', action);
320332
}
321333

322-
if (options?.locale) {
323-
params.set('ui_locales', options.locale);
334+
if (locale) {
335+
params.set('ui_locales', locale);
324336
}
325337

326338
if (this?.pkceMethod && !!pkceChallenge) {
@@ -330,6 +342,10 @@ export class KeycloakClient implements KeycloakInstance {
330342

331343
this.callbackStorage!.add(callbackState);
332344

345+
Object.keys(rest).forEach((key) => {
346+
params.set(key, `${rest[key]}`);
347+
});
348+
333349
return `${baseUrl}?${formatQuerystringParameters(params)}`;
334350
}
335351

0 commit comments

Comments
 (0)