Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit d028832

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 2c3fb25 + 4ae7f99 commit d028832

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

plugins/auth-oauth2/src/grants/implicit.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function getImplicit(
3131
}
3232

3333
const authorizationUrl = new URL(`${authorizationUrlRaw ?? ''}`);
34-
authorizationUrl.searchParams.set('response_type', 'code');
34+
authorizationUrl.searchParams.set('response_type', 'token');
3535
authorizationUrl.searchParams.set('client_id', clientId);
3636
if (redirectUri) authorizationUrl.searchParams.set('redirect_uri', redirectUri);
3737
if (scope) authorizationUrl.searchParams.set('scope', scope);
@@ -42,25 +42,33 @@ export function getImplicit(
4242
}
4343

4444
const authorizationUrlStr = authorizationUrl.toString();
45+
let foundAccessToken = false;
4546
let { close } = await ctx.window.openUrl({
4647
url: authorizationUrlStr,
4748
label: 'oauth-authorization-url',
49+
async onClose() {
50+
if (!foundAccessToken) {
51+
reject(new Error('Authorization window closed'));
52+
}
53+
},
4854
async onNavigate({ url: urlStr }) {
4955
const url = new URL(urlStr);
5056
if (url.searchParams.has('error')) {
5157
return reject(Error(`Failed to authorize: ${url.searchParams.get('error')}`));
5258
}
5359

54-
// Close the window here, because we don't need it anymore
55-
close();
56-
5760
const hash = url.hash.slice(1);
5861
const params = new URLSearchParams(hash);
59-
const idToken = params.get('id_token');
60-
if (idToken) {
61-
params.set('access_token', idToken);
62-
params.delete('id_token');
62+
63+
const accessToken = params.get('access_token');
64+
if (!accessToken) {
65+
return;
6366
}
67+
foundAccessToken = true;
68+
69+
// Close the window here, because we don't need it anymore
70+
close();
71+
6472
const response = Object.fromEntries(params) as unknown as AccessTokenRawResponse;
6573
try {
6674
resolve(await storeToken(ctx, contextId, response));

0 commit comments

Comments
 (0)