@@ -155,7 +155,8 @@ func NewAuthService(userUC *biz.UserUseCase, orgUC *biz.OrganizationUseCase, mUC
155155}
156156
157157type AuthURLs struct {
158- Login , callback string
158+ Login , callback string
159+ loginIsOverridden bool
159160}
160161
161162// urlScheme is deprecated, now it will be inferred from the serverConfig externalURL
@@ -179,6 +180,8 @@ func getAuthURLs(serverConfig *conf.Server_HTTP, loginURLOverride string) (*Auth
179180 // Override the login URL if needed
180181 if loginURLOverride != "" {
181182 urls .Login = loginURLOverride
183+ // denote it's been overridden
184+ urls .loginIsOverridden = true
182185 }
183186
184187 return urls , nil
@@ -274,8 +277,14 @@ func (c *upstreamOIDCclaims) preferredEmail() string {
274277
275278func callbackHandler (svc * AuthService , w http.ResponseWriter , r * http.Request ) * oauthResp {
276279 ctx := context .Background ()
277- // if OIDC provider returns an error, redirect to the login page to and show it to the user
280+ // if OIDC provider returns an error, show the error to the user
278281 if desc := r .URL .Query ().Get (oidcErrorParam ); desc != "" {
282+ // Do not redirect if there is no dedicated login page
283+ if ! svc .AuthURLs .loginIsOverridden {
284+ return newOauthResp (http .StatusUnauthorized , errors .New (desc ), true )
285+ }
286+
287+ // redirect to the login page to and show it to the user
279288 redirectURL , err := url .Parse (svc .AuthURLs .Login )
280289 if err != nil {
281290 return newOauthResp (http .StatusInternalServerError , fmt .Errorf ("failed to redirect to login: %w" , err ), false )
@@ -285,7 +294,7 @@ func callbackHandler(svc *AuthService, w http.ResponseWriter, r *http.Request) *
285294 q .Set (oidcErrorParam , desc )
286295 redirectURL .RawQuery = q .Encode ()
287296
288- return & oauthResp {http .StatusUnauthorized , errors . New ( desc ) , true , redirectURL }
297+ return & oauthResp {http .StatusUnauthorized , nil , true , redirectURL }
289298 }
290299
291300 // Get information from google OIDC token
0 commit comments