Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/authentication/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ async function authorizationCodeCallback(config: DefaultClientConfiguration, cod
return atoken;
}

async function refreshAuth(extraParams: Record<string, string>) {
const config = getConfig();
const auth = {
...config
};
const req = jso_getAuthRequest(auth.provider, auth.scope);
console.log(config.redirect_uri);
let pkce: PKCERequest;
pkce = await generatePKCE();

req["code_challenge"] = pkce.codeChallenge;
req["code_challenge_method"] = "S256";
delete req.prompt
delete req.response_mode

if (window.top) {
const authUrl = encodeURL(auth.authorization, {...req, ...extraParams});

window.top.location.href = authUrl
}
}

function logInWithRedirect(reset: boolean = false, extraParams?: Record<string, string>) {
console.log("In redirect...");
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -236,7 +258,7 @@ function logInWithRedirect(reset: boolean = false, extraParams?: Record<string,
} catch {}
}

const authUrl = encodeURL(auth.authorization, {...req, ...extraParams});
const authUrl = encodeURL(auth.authorization, req);

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

if (config?.extra_params && Object.entries(config.extra_params).length) {
return logInWithRedirect(reset, config.extra_params);
return refreshAuth(config.extra_params);
}

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

return logInWithRedirect(reset, config?.extra_params);
return logInWithRedirect(reset);
};