mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 17:48:30 +02:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -31,7 +31,7 @@ export function getImplicit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const authorizationUrl = new URL(`${authorizationUrlRaw ?? ''}`);
|
const authorizationUrl = new URL(`${authorizationUrlRaw ?? ''}`);
|
||||||
authorizationUrl.searchParams.set('response_type', 'code');
|
authorizationUrl.searchParams.set('response_type', 'token');
|
||||||
authorizationUrl.searchParams.set('client_id', clientId);
|
authorizationUrl.searchParams.set('client_id', clientId);
|
||||||
if (redirectUri) authorizationUrl.searchParams.set('redirect_uri', redirectUri);
|
if (redirectUri) authorizationUrl.searchParams.set('redirect_uri', redirectUri);
|
||||||
if (scope) authorizationUrl.searchParams.set('scope', scope);
|
if (scope) authorizationUrl.searchParams.set('scope', scope);
|
||||||
@@ -42,25 +42,33 @@ export function getImplicit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const authorizationUrlStr = authorizationUrl.toString();
|
const authorizationUrlStr = authorizationUrl.toString();
|
||||||
|
let foundAccessToken = false;
|
||||||
let { close } = await ctx.window.openUrl({
|
let { close } = await ctx.window.openUrl({
|
||||||
url: authorizationUrlStr,
|
url: authorizationUrlStr,
|
||||||
label: 'oauth-authorization-url',
|
label: 'oauth-authorization-url',
|
||||||
|
async onClose() {
|
||||||
|
if (!foundAccessToken) {
|
||||||
|
reject(new Error('Authorization window closed'));
|
||||||
|
}
|
||||||
|
},
|
||||||
async onNavigate({ url: urlStr }) {
|
async onNavigate({ url: urlStr }) {
|
||||||
const url = new URL(urlStr);
|
const url = new URL(urlStr);
|
||||||
if (url.searchParams.has('error')) {
|
if (url.searchParams.has('error')) {
|
||||||
return reject(Error(`Failed to authorize: ${url.searchParams.get('error')}`));
|
return reject(Error(`Failed to authorize: ${url.searchParams.get('error')}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hash = url.hash.slice(1);
|
||||||
|
const params = new URLSearchParams(hash);
|
||||||
|
|
||||||
|
const accessToken = params.get('access_token');
|
||||||
|
if (!accessToken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foundAccessToken = true;
|
||||||
|
|
||||||
// Close the window here, because we don't need it anymore
|
// Close the window here, because we don't need it anymore
|
||||||
close();
|
close();
|
||||||
|
|
||||||
const hash = url.hash.slice(1);
|
|
||||||
const params = new URLSearchParams(hash);
|
|
||||||
const idToken = params.get('id_token');
|
|
||||||
if (idToken) {
|
|
||||||
params.set('access_token', idToken);
|
|
||||||
params.delete('id_token');
|
|
||||||
}
|
|
||||||
const response = Object.fromEntries(params) as unknown as AccessTokenRawResponse;
|
const response = Object.fromEntries(params) as unknown as AccessTokenRawResponse;
|
||||||
try {
|
try {
|
||||||
resolve(await storeToken(ctx, contextId, response));
|
resolve(await storeToken(ctx, contextId, response));
|
||||||
|
|||||||
Reference in New Issue
Block a user