From adcaf83723ed62b6dd85972d50c699752a4f9a71 Mon Sep 17 00:00:00 2001 From: Giuseppe Regina Date: Wed, 2 Oct 2024 11:25:54 +0200 Subject: [PATCH] Uses suggested style to discriminate PKCE case --- controller/v1/user.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/controller/v1/user.go b/controller/v1/user.go index b909a9f0..054a67b4 100644 --- a/controller/v1/user.go +++ b/controller/v1/user.go @@ -421,17 +421,18 @@ func (uc *UserController) RedirecToSericeAuth(c echo.Context) error { logger.Debug("Doing URL for provider:", providerName) - u := "" - if config.Setting.OAUTH2_SETTINGS.UsePkce == true { - u = config.Setting.MAIN_SETTINGS.OAuth2Config.AuthCodeURL(config.Setting.OAUTH2_SETTINGS.StateValue, - oauth2.SetAuthURLParam("response_type", config.Setting.OAUTH2_SETTINGS.ResponseType), + options := []oauth2.AuthCodeOption{ + oauth2.SetAuthURLParam("response_type", config.Setting.OAUTH2_SETTINGS.ResponseType), + } + + if config.Setting.OAUTH2_SETTINGS.UsePkce { + options = append(options, oauth2.SetAuthURLParam("code_challenge", heputils.GenCodeChallengeS256(config.Setting.OAUTH2_SETTINGS.UserToken)), oauth2.SetAuthURLParam("code_challenge_method", "S256")) - } else { - u = config.Setting.MAIN_SETTINGS.OAuth2Config.AuthCodeURL(config.Setting.OAUTH2_SETTINGS.StateValue, - oauth2.SetAuthURLParam("response_type", config.Setting.OAUTH2_SETTINGS.ResponseType)) } + u := config.Setting.MAIN_SETTINGS.OAuth2Config.AuthCodeURL(config.Setting.OAUTH2_SETTINGS.StateValue, options...) + logger.Debug("RedirecToSericeAuth Redirecting URL :", u) return c.Redirect(http.StatusFound, u)