fix: Make secret optional when using PKCE (#525)

Signed-off-by: Steve0x2a <stevesough@gmail.com>
This commit is contained in:
Steve0x2a 2022-03-02 13:15:14 +08:00 committed by GitHub
parent 18aa70dfb2
commit 22f5ad06ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -444,18 +444,27 @@ func GetAuthorizationCodeToken(application *Application, clientSecret string, co
// anti replay attacks
return nil, errors.New("error: authorization code has been used")
}
if token.CodeChallenge != "" && pkceChallenge(verifier) != token.CodeChallenge {
return nil, errors.New("error: incorrect code_verifier")
}
if application.ClientSecret != clientSecret {
return nil, errors.New("error: invalid client_secret")
// when using PKCE, the Client Secret can be empty,
// but if it is provided, it must be accurate.
if token.CodeChallenge == "" {
return nil, errors.New("error: invalid client_secret")
} else {
if clientSecret != "" {
return nil, errors.New("error: invalid client_secret")
}
}
}
if application.Name != token.Application {
return nil, errors.New("error: the token is for wrong application (client_id)")
}
if token.CodeChallenge != "" && pkceChallenge(verifier) != token.CodeChallenge {
return nil, errors.New("error: incorrect code_verifier")
}
if time.Now().Unix() > token.CodeExpireIn {
// code must be used within 5 minutes
return nil, errors.New("error: authorization code has expired")