feat: add PKCE support (#434)

* feat: add PKCE support

Signed-off-by: Steve0x2a <stevesough@gmail.com>

* fix: error output when challenge is empty

Signed-off-by: Steve0x2a <stevesough@gmail.com>
This commit is contained in:
Steve0x2a
2022-01-21 09:29:19 +08:00
committed by GitHub
parent 339a85e4b0
commit 630b84f534
5 changed files with 68 additions and 25 deletions

View File

@ -44,7 +44,7 @@ function oAuthParamsToQuery(oAuthParams) {
}
// code
return `?clientId=${oAuthParams.clientId}&responseType=${oAuthParams.responseType}&redirectUri=${oAuthParams.redirectUri}&scope=${oAuthParams.scope}&state=${oAuthParams.state}&nonce=${oAuthParams.nonce}`;
return `?clientId=${oAuthParams.clientId}&responseType=${oAuthParams.responseType}&redirectUri=${oAuthParams.redirectUri}&scope=${oAuthParams.scope}&state=${oAuthParams.state}&nonce=${oAuthParams.nonce}&code_challenge_method=${oAuthParams.challengeMethod}&code_challenge=${oAuthParams.codeChallenge}`;
}
export function getApplicationLogin(oAuthParams) {

View File

@ -83,7 +83,9 @@ export function getOAuthGetParameters(params) {
const scope = queries.get("scope");
const state = queries.get("state");
const nonce = queries.get("nonce")
const challengeMethod = queries.get("code_challenge_method")
const codeChallenge = queries.get("code_challenge")
if (clientId === undefined || clientId === null) {
// login
return null;
@ -96,6 +98,8 @@ export function getOAuthGetParameters(params) {
scope: scope,
state: state,
nonce: nonce,
challengeMethod: challengeMethod,
codeChallenge: codeChallenge,
};
}
}