@@ -574,7 +574,7 @@ func SignInOAuth(ctx *context.Context) {
574
574
user , gothUser , err := oAuth2UserLoginCallback (loginSource , ctx .Req , ctx .Resp )
575
575
if err == nil && user != nil {
576
576
// we got the user without going through the whole OAuth2 authentication flow again
577
- handleOAuth2SignIn (ctx , user , gothUser )
577
+ handleOAuth2SignIn (ctx , loginSource , user , gothUser )
578
578
return
579
579
}
580
580
@@ -660,7 +660,7 @@ func SignInOAuthCallback(ctx *context.Context) {
660
660
}
661
661
}
662
662
663
- handleOAuth2SignIn (ctx , u , gothUser )
663
+ handleOAuth2SignIn (ctx , loginSource , u , gothUser )
664
664
}
665
665
666
666
func getUserName (gothUser * goth.User ) string {
@@ -702,18 +702,22 @@ func updateAvatarIfNeed(url string, u *models.User) {
702
702
}
703
703
}
704
704
705
- func handleOAuth2SignIn (ctx * context.Context , u * models.User , gothUser goth.User ) {
705
+ func handleOAuth2SignIn (ctx * context.Context , source * models. LoginSource , u * models.User , gothUser goth.User ) {
706
706
updateAvatarIfNeed (gothUser .AvatarURL , u )
707
707
708
- // If this user is enrolled in 2FA, we can't sign the user in just yet.
709
- // Instead, redirect them to the 2FA authentication page.
710
- _ , err := models .GetTwoFactorByUID (u .ID )
711
- if err != nil {
712
- if ! models .IsErrTwoFactorNotEnrolled (err ) {
708
+ needs2FA := false
709
+ if ! source .Cfg .(* oauth2.Source ).OverrideLocalTwoFA {
710
+ _ , err := models .GetTwoFactorByUID (u .ID )
711
+ if err != nil && ! models .IsErrTwoFactorNotEnrolled (err ) {
713
712
ctx .ServerError ("UserSignIn" , err )
714
713
return
715
714
}
715
+ needs2FA = err == nil
716
+ }
716
717
718
+ // If this user is enrolled in 2FA and this source doesn't override it,
719
+ // we can't sign the user in just yet. Instead, redirect them to the 2FA authentication page.
720
+ if ! needs2FA {
717
721
if err := ctx .Session .Set ("uid" , u .ID ); err != nil {
718
722
log .Error ("Error setting uid in session: %v" , err )
719
723
}
0 commit comments