Skip to content

Commit a9cc052

Browse files
committed
[wip]
1 parent a7066c0 commit a9cc052

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/authentication/connector.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,28 @@ async function authorizationCodeCallback(config: DefaultClientConfiguration, cod
167167
return atoken;
168168
}
169169

170+
async function refreshAuth(extraParams: Record<string, string>) {
171+
const config = getConfig();
172+
const auth = {
173+
...config
174+
};
175+
const req = jso_getAuthRequest(auth.provider, auth.scope);
176+
console.log(config.redirect_uri);
177+
let pkce: PKCERequest;
178+
pkce = await generatePKCE();
179+
180+
req["code_challenge"] = pkce.codeChallenge;
181+
req["code_challenge_method"] = "S256";
182+
delete req.prompt
183+
delete req.response_mode
184+
185+
if (window.top) {
186+
const authUrl = encodeURL(auth.authorization, {...req, ...extraParams});
187+
188+
window.top.location.href = authUrl
189+
}
190+
}
191+
170192
function logInWithRedirect(reset: boolean = false, extraParams?: Record<string, string>) {
171193
console.log("In redirect...");
172194
return new Promise(async (resolve, reject) => {
@@ -236,7 +258,7 @@ function logInWithRedirect(reset: boolean = false, extraParams?: Record<string,
236258
} catch {}
237259
}
238260

239-
const authUrl = encodeURL(auth.authorization, {...req, ...extraParams});
261+
const authUrl = encodeURL(auth.authorization, req);
240262

241263
const iframe = createIFrame(authUrl, {
242264
sandbox: "allow-same-origin"
@@ -483,7 +505,7 @@ export default (token?: string, reset: boolean = false, config?: Partial<ClientC
483505
}
484506

485507
if (config?.extra_params && Object.entries(config.extra_params).length) {
486-
return logInWithRedirect(reset, config.extra_params);
508+
return refreshAuth(config.extra_params);
487509
}
488510

489511
if (config?.response_mode === "web_message" && config.prompt === "none") {
@@ -494,6 +516,6 @@ export default (token?: string, reset: boolean = false, config?: Partial<ClientC
494516
return logInWithPopUp(reset);
495517
}
496518

497-
return logInWithRedirect(reset, config?.extra_params);
519+
return logInWithRedirect(reset);
498520
};
499521

0 commit comments

Comments
 (0)