Skip to content

Commit

Permalink
feat: support PKCE
Browse files Browse the repository at this point in the history
Feature is available in oauth2 lib since v0.21.0
  • Loading branch information
mougams committed Jun 21, 2024
1 parent 788ff71 commit c0930a5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/auth/authenticator_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type OIDCAuthenticator struct {

signatureComputer *HmacSha256Computer
encryptor *AESEncryptor
pkceVerifier string

options OIDCAuthenticatorOptions
}
Expand Down Expand Up @@ -117,6 +118,7 @@ func NewOIDCAuthenticator(options OIDCAuthenticatorOptions) *OIDCAuthenticator {
options: options,
signatureComputer: NewHmacSha256Computer(options.SignatureSecret),
encryptor: NewAESEncryptor(options.EncryptionSecret),
pkceVerifier: oauth2.GenerateVerifier(),
}

go func() {
Expand Down Expand Up @@ -346,7 +348,7 @@ func (oa *OIDCAuthenticator) Authenticate(msg *message.Message) (bool, []action.

var authorizationURL string
err = oa.withOAuth2Config(domain, func(config oauth2.Config) error {
authorizationURL = config.AuthCodeURL(base64.StdEncoding.EncodeToString(stateBytes))
authorizationURL = config.AuthCodeURL(base64.StdEncoding.EncodeToString(stateBytes), oauth2.S256ChallengeOption(oa.pkceVerifier))
return nil
})
if err != nil {
Expand Down Expand Up @@ -386,7 +388,7 @@ func (oa *OIDCAuthenticator) handleOAuth2Callback(tmpl *template.Template, error

var oauth2Token *oauth2.Token
err := oa.withOAuth2Config(domain, func(config oauth2.Config) error {
token, err := config.Exchange(r.Context(), r.URL.Query().Get("code"))
token, err := config.Exchange(r.Context(), r.URL.Query().Get("code"), oauth2.VerifierOption(oa.pkceVerifier))
oauth2Token = token
return err
})
Expand Down

0 comments on commit c0930a5

Please sign in to comment.