Skip to content

Commit 07754f5

Browse files
fix(oidc): refresh silent signin scope=null (release) (#1503)
1 parent 2c08373 commit 07754f5

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

packages/oidc-client/src/keepSession.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export const tryKeepSessionAsync = async (oidc: Oidc) => {
3030
oidc.tokens = tokens;
3131
const getLoginParams = serviceWorker.getLoginParams(oidc.configurationName);
3232
// @ts-ignore
33-
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, getLoginParams.extras);
33+
oidc.timeoutId = autoRenewTokens(
34+
oidc,
35+
oidc.tokens.expiresAt,
36+
getLoginParams.extras,
37+
getLoginParams.scope,
38+
);
3439
const sessionState = await serviceWorker.getSessionStateAsync();
3540
// @ts-ignore
3641
await oidc.startCheckSessionAsync(
@@ -64,7 +69,12 @@ export const tryKeepSessionAsync = async (oidc: Oidc) => {
6469
oidc.tokens = setTokens(tokens, null, configuration.token_renew_mode);
6570
const getLoginParams = session.getLoginParams();
6671
// @ts-ignore
67-
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, getLoginParams.extras);
72+
oidc.timeoutId = autoRenewTokens(
73+
oidc,
74+
oidc.tokens.expiresAt,
75+
getLoginParams.extras,
76+
getLoginParams.scope,
77+
);
6878
const sessionState = await session.getSessionStateAsync();
6979
// @ts-ignore
7080
await oidc.startCheckSessionAsync(

packages/oidc-client/src/login.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ export const defaultLoginAsync =
6363
);
6464
let storage;
6565
if (serviceWorker) {
66-
serviceWorker.setLoginParams({ callbackPath: url, extras: originExtras });
66+
serviceWorker.setLoginParams({ callbackPath: url, extras: originExtras, scope: scope });
6767
await serviceWorker.initAsync(oidcServerConfiguration, 'loginAsync', configuration);
6868
await serviceWorker.setNonceAsync(nonce);
6969
serviceWorker.startKeepAliveServiceWorker();
7070
storage = serviceWorker;
7171
} else {
7272
const session = initSession(configurationName, configuration.storage ?? sessionStorage);
73-
session.setLoginParams({ callbackPath: url, extras: originExtras });
73+
session.setLoginParams({ callbackPath: url, extras: originExtras, scope: scope });
7474
await session.setNonceAsync(nonce);
7575
storage = session;
7676
}
@@ -139,24 +139,24 @@ export const loginCallbackAsync =
139139
storage = session;
140140
}
141141

142-
const params = getParseQueryStringFromLocation(href);
143-
144-
if (params.error || params.error_description) {
145-
throw new Error(`Error from OIDC server: ${params.error} - ${params.error_description}`);
142+
if (queryParams.error || queryParams.error_description) {
143+
throw new Error(
144+
`Error from OIDC server: ${queryParams.error} - ${queryParams.error_description}`,
145+
);
146146
}
147147

148-
if (params.iss && params.iss !== oidcServerConfiguration.issuer) {
148+
if (queryParams.iss && queryParams.iss !== oidcServerConfiguration.issuer) {
149149
console.error();
150150
throw new Error(
151-
`Issuer not valid (expected: ${oidcServerConfiguration.issuer}, received: ${params.iss})`,
151+
`Issuer not valid (expected: ${oidcServerConfiguration.issuer}, received: ${queryParams.iss})`,
152152
);
153153
}
154-
if (params.state && params.state !== state) {
155-
throw new Error(`State not valid (expected: ${state}, received: ${params.state})`);
154+
if (queryParams.state && queryParams.state !== state) {
155+
throw new Error(`State not valid (expected: ${state}, received: ${queryParams.state})`);
156156
}
157157

158158
const data = {
159-
code: params.code,
159+
code: queryParams.code,
160160
grant_type: 'authorization_code',
161161
client_id: configuration.client_id,
162162
redirect_uri: redirectUri,
@@ -269,6 +269,8 @@ export const loginCallbackAsync =
269269
tokens: formattedTokens,
270270
state: 'request.state',
271271
callbackPath: loginParams.callbackPath,
272+
scope: queryParams.scope,
273+
extras: loginParams.extras,
272274
};
273275
} catch (exception) {
274276
console.error(exception);

packages/oidc-client/src/oidc.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ export type LoginCallback = {
7373

7474
export type InternalLoginCallback = {
7575
callbackPath: string;
76+
state: string;
7677
parsedTokens: Tokens;
78+
scope: string;
79+
extras: StringMap;
7780
};
7881

7982
const loginCallbackWithAutoTokensRenewAsync = async (oidc): Promise<LoginCallback> => {
80-
const { parsedTokens, callbackPath } = await oidc.loginCallbackAsync();
81-
oidc.timeoutId = autoRenewTokens(oidc, parsedTokens.expiresAt);
83+
const { parsedTokens, callbackPath, extras, scope } = await oidc.loginCallbackAsync();
84+
oidc.timeoutId = autoRenewTokens(oidc, parsedTokens.expiresAt, extras, scope);
8285
return { callbackPath };
8386
};
8487

@@ -355,7 +358,13 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
355358
await this.userInfoAsync();
356359
}
357360
// @ts-ignore
358-
return { parsedTokens, state: response.state, callbackPath: response.callbackPath };
361+
return {
362+
parsedTokens,
363+
state: response.state,
364+
callbackPath: response.callbackPath,
365+
scope: response.scope,
366+
extras: response.extras,
367+
};
359368
};
360369
this.loginCallbackPromise = loginCallbackLocalAsync();
361370
return this.loginCallbackPromise.finally(() => {
@@ -427,6 +436,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
427436
}
428437
timer.clearTimeout(this.timeoutId);
429438
// @ts-ignore
439+
430440
this.renewTokensPromise = renewTokensAndStartTimerAsync(this, true, extras, scope);
431441
return this.renewTokensPromise.finally(() => {
432442
this.renewTokensPromise = null;

packages/oidc-client/src/silentLogin.ts

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export const _silentLoginAsync =
2525
if (!configuration.silent_redirect_uri || !configuration.silent_login_uri) {
2626
return Promise.resolve(null);
2727
}
28-
2928
try {
3029
publishEvent(eventNames.silentLoginAsync_begin, {});
3130
let queries = '';

0 commit comments

Comments
 (0)