Skip to content

Commit a3366c4

Browse files
committed
Refactored handleOAuth2SignIn in routers/user/auth.go
The function handleOAuth2SignIn was called twice but some code path could only be reached by one of the invocations. Moved the unnecessary code path out of handleOAuth2SignIn. Signed-off-by: Martin Michaelis <[email protected]>
1 parent 8db3bdc commit a3366c4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

routers/user/auth.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ func SignInOAuth(ctx *context.Context) {
508508
}
509509

510510
// try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
511-
user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
511+
user, _, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
512512
if err == nil && user != nil {
513513
// we got the user without going through the whole OAuth2 authentication flow again
514-
handleOAuth2SignIn(user, gothUser, ctx, err)
514+
handleOAuth2SignIn(ctx, user)
515515
return
516516
}
517517

@@ -540,10 +540,6 @@ func SignInOAuthCallback(ctx *context.Context) {
540540

541541
u, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req.Request, ctx.Resp)
542542

543-
handleOAuth2SignIn(u, gothUser, ctx, err)
544-
}
545-
546-
func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context, err error) {
547543
if err != nil {
548544
ctx.ServerError("UserSignIn", err)
549545
return
@@ -556,9 +552,13 @@ func handleOAuth2SignIn(u *models.User, gothUser goth.User, ctx *context.Context
556552
return
557553
}
558554

555+
handleOAuth2SignIn(ctx, u)
556+
}
557+
558+
func handleOAuth2SignIn(ctx *context.Context, u *models.User) {
559559
// If this user is enrolled in 2FA, we can't sign the user in just yet.
560560
// Instead, redirect them to the 2FA authentication page.
561-
_, err = models.GetTwoFactorByUID(u.ID)
561+
_, err := models.GetTwoFactorByUID(u.ID)
562562
if err != nil {
563563
if models.IsErrTwoFactorNotEnrolled(err) {
564564
ctx.Session.Set("uid", u.ID)

0 commit comments

Comments
 (0)