@@ -155,7 +155,8 @@ func NewAuthService(userUC *biz.UserUseCase, orgUC *biz.OrganizationUseCase, mUC
155
155
}
156
156
157
157
type AuthURLs struct {
158
- Login , callback string
158
+ Login , callback string
159
+ loginIsOverridden bool
159
160
}
160
161
161
162
// 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
179
180
// Override the login URL if needed
180
181
if loginURLOverride != "" {
181
182
urls .Login = loginURLOverride
183
+ // denote it's been overridden
184
+ urls .loginIsOverridden = true
182
185
}
183
186
184
187
return urls , nil
@@ -274,8 +277,14 @@ func (c *upstreamOIDCclaims) preferredEmail() string {
274
277
275
278
func callbackHandler (svc * AuthService , w http.ResponseWriter , r * http.Request ) * oauthResp {
276
279
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
278
281
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
279
288
redirectURL , err := url .Parse (svc .AuthURLs .Login )
280
289
if err != nil {
281
290
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) *
285
294
q .Set (oidcErrorParam , desc )
286
295
redirectURL .RawQuery = q .Encode ()
287
296
288
- return & oauthResp {http .StatusUnauthorized , errors . New ( desc ) , true , redirectURL }
297
+ return & oauthResp {http .StatusUnauthorized , nil , true , redirectURL }
289
298
}
290
299
291
300
// Get information from google OIDC token
0 commit comments