@@ -656,6 +656,23 @@ func SignInOAuthCallback(ctx *context.Context) {
656
656
handleOAuth2SignIn (ctx , loginSource , u , gothUser )
657
657
}
658
658
659
+ func claimValueToStringSlice (claimValue interface {}) []string {
660
+ var groups []string
661
+
662
+ switch rawGroup := claimValue .(type ) {
663
+ case []string :
664
+ groups = rawGroup
665
+ default :
666
+ str := fmt .Sprintf ("%s" , rawGroup )
667
+ if strings .Contains (str , "," ) {
668
+ groups = strings .Split (str , "," )
669
+ } else {
670
+ groups = []string {str }
671
+ }
672
+ }
673
+ return groups
674
+ }
675
+
659
676
func setUserGroupClaims (loginSource * models.LoginSource , u * models.User , gothUser * goth.User ) bool {
660
677
661
678
source := loginSource .Cfg .(* oauth2.Source )
@@ -668,18 +685,7 @@ func setUserGroupClaims(loginSource *models.LoginSource, u *models.User, gothUse
668
685
return false
669
686
}
670
687
671
- var groups []string
672
-
673
- switch rawGroup := groupClaims .(type ) {
674
- case []string :
675
- groups = rawGroup
676
- case string :
677
- if strings .Contains (rawGroup , "," ) {
678
- groups = strings .Split (rawGroup , "," )
679
- } else {
680
- groups = []string {rawGroup }
681
- }
682
- }
688
+ groups := claimValueToStringSlice (groupClaims )
683
689
684
690
wasAdmin , wasRestricted := u .IsAdmin , u .IsRestricted
685
691
@@ -844,9 +850,23 @@ func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Requ
844
850
845
851
if oauth2Source .RequiredClaimName != "" {
846
852
claimInterface , has := gothUser .RawData [oauth2Source .RequiredClaimName ]
847
- if ! has || ( oauth2Source . RequiredClaimValue != "" && claimInterface .( string ) != oauth2Source . RequiredClaimValue ) {
853
+ if ! has {
848
854
return nil , goth.User {}, models.ErrUserProhibitLogin {Name : gothUser .UserID }
849
855
}
856
+
857
+ if oauth2Source .RequiredClaimValue != "" {
858
+ groups := claimValueToStringSlice (claimInterface )
859
+ found := false
860
+ for _ , group := range groups {
861
+ if group == oauth2Source .RequiredClaimValue {
862
+ found = true
863
+ break
864
+ }
865
+ }
866
+ if ! found {
867
+ return nil , goth.User {}, models.ErrUserProhibitLogin {Name : gothUser .UserID }
868
+ }
869
+ }
850
870
}
851
871
852
872
user := & models.User {
0 commit comments