Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ceaf11c
Add setting to OAuth handlers to override local 2FA settings
zeripath Aug 21, 2021
ddc1966
Fix regression from #16544
zeripath Aug 20, 2021
ca74f82
Add scopes settings
zeripath Aug 20, 2021
c282f85
fix trace logging in auth_openid
zeripath Aug 20, 2021
0d4874f
add required claim options
zeripath Aug 20, 2021
bd86307
Move UpdateExternalUser to externalaccount
zeripath Aug 20, 2021
0e27070
Allow OAuth2/OIDC to set Admin/Restricted status
zeripath Aug 20, 2021
b51c09c
Allow use of the same group claim name for the prohibit login value
zeripath Aug 21, 2021
11791e5
fixup! Move UpdateExternalUser to externalaccount
zeripath Aug 21, 2021
de07c25
Merge branch 'main' into oidc-claims
zeripath Aug 29, 2021
ea37fd0
Merge branch 'main' into oidc-claims
zeripath Aug 29, 2021
a730e6b
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Sep 25, 2021
4818a72
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Sep 27, 2021
8b8abaa
as per wxiaoguang
zeripath Sep 27, 2021
7a88d06
add label back in
zeripath Oct 14, 2021
1f0d1a0
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Oct 14, 2021
7cd84d7
adjust localisation
zeripath Oct 14, 2021
d119bc8
Merge branch 'main' into oidc-claims
6543 Oct 15, 2021
125747a
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Nov 20, 2021
a5d3887
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Nov 27, 2021
7545100
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Nov 28, 2021
47ae8f5
placate lint
zeripath Nov 28, 2021
3f4df7c
Merge branch 'main' into oidc-claims
lunny Dec 10, 2021
bc558ed
Merge branch 'main' into oidc-claims
lunny Dec 10, 2021
36da1a6
Merge branch 'main' into oidc-claims
lunny Dec 13, 2021
6041ea8
Merge branch 'main' into oidc-claims
lunny Dec 13, 2021
706532a
Merge remote-tracking branch 'origin/main' into oidc-claims
zeripath Dec 13, 2021
33e3af2
Merge branch 'main' into oidc-claims
lunny Dec 14, 2021
323782f
Merge branch 'main' into oidc-claims
techknowlogick Dec 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into oidc-claims
  • Loading branch information
zeripath committed Sep 25, 2021
commit a730e6b103fbc028c1420d4870bb911215ff212a
6 changes: 3 additions & 3 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ var (
Usage: "Custom icon URL for OAuth2 login source",
},
cli.BoolFlag{
Name: "override-local-2fa",
Usage: "Set to true to override local 2fa settings",
Name: "skip-local-2fa",
Usage: "Set to true to skip local 2fa for users authenticated by this source",
},
cli.StringSliceFlag{
Name: "scopes",
Expand Down Expand Up @@ -653,7 +653,7 @@ func parseOAuth2Config(c *cli.Context) *oauth2.Source {
OpenIDConnectAutoDiscoveryURL: c.String("auto-discover-url"),
CustomURLMapping: customURLMapping,
IconURL: c.String("icon-url"),
OverrideLocalTwoFA: c.Bool("override-local-2fa"),
SkipLocalTwoFA: c.Bool("skip-local-2fa"),
Scopes: c.StringSlice("scopes"),
RequiredClaimName: c.String("required-claim-name"),
RequiredClaimValue: c.String("required-claim-value"),
Expand Down
5 changes: 2 additions & 3 deletions models/external_login_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/structs"

"xorm.io/builder"
Expand Down Expand Up @@ -106,7 +105,7 @@ func GetUserIDByExternalUserID(provider, userID string) (int64, error) {

// UpdateExternalUserByExternalID updates an external user's information
func UpdateExternalUserByExternalID(external *ExternalLoginUser) error {
has, err := x.Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID).
has, err := db.GetEngine(db.DefaultContext).Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID).
NoAutoCondition().
Exist(external)
if err != nil {
Expand All @@ -115,7 +114,7 @@ func UpdateExternalUserByExternalID(external *ExternalLoginUser) error {
return ErrExternalLoginUserNotExist{external.UserID, external.LoginSourceID}
}

_, err = x.Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID).AllCols().Update(external)
_, err = db.GetEngine(db.DefaultContext).Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID).AllCols().Update(external)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2458,8 +2458,8 @@ auths.oauth2_tokenURL = Token URL
auths.oauth2_authURL = Authorize URL
auths.oauth2_profileURL = Profile URL
auths.oauth2_emailURL = Email URL
auths.override_local_two_fa = Override local 2FA
auths.override_local_two_fa_helper = Leaving unset means local users with 2FA set will still have to pass 2FA to log on
auths.skip_local_two_fa = Skip local 2FA
auths.skip_local_two_fa_helper = Leaving unset means local users with 2FA set will still have to pass 2FA to log on
auths.oauth2_tenant = Tenant
auths.oauth2_scopes = Additional Scopes
auths.oauth2_required_claim_name = Required Claim Name
Expand Down
2 changes: 1 addition & 1 deletion routers/web/admin/auths.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source {
OpenIDConnectAutoDiscoveryURL: form.OpenIDConnectAutoDiscoveryURL,
CustomURLMapping: customURLMapping,
IconURL: form.Oauth2IconURL,
OverrideLocalTwoFA: form.OverrideLocalTwoFA,
Scopes: strings.Split(form.Oauth2Scopes, ","),
RequiredClaimName: form.Oauth2RequiredClaimName,
RequiredClaimValue: form.Oauth2RequiredClaimValue,
SkipLocalTwoFA: form.SkipLocalTwoFA,
}
}

Expand Down
8 changes: 4 additions & 4 deletions routers/web/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func claimValueToStringSlice(claimValue interface{}) []string {
return groups
}

func setUserGroupClaims(loginSource *models.LoginSource, u *models.User, gothUser *goth.User) bool {
func setUserGroupClaims(loginSource *login.Source, u *models.User, gothUser *goth.User) bool {

source := loginSource.Cfg.(*oauth2.Source)
if source.GroupClaimName == "" || (source.AdminGroup == "" && source.RestrictedGroup == "") {
Expand Down Expand Up @@ -756,11 +756,11 @@ func updateAvatarIfNeed(url string, u *models.User) {
}
}

func handleOAuth2SignIn(ctx *context.Context, source *models.LoginSource, u *models.User, gothUser goth.User) {
func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.User, gothUser goth.User) {
updateAvatarIfNeed(gothUser.AvatarURL, u)

needs2FA := false
if !source.Cfg.(*oauth2.Source).OverrideLocalTwoFA {
if !source.Cfg.(*oauth2.Source).SkipLocalTwoFA {
_, err := models.GetTwoFactorByUID(u.ID)
if err != nil && !models.IsErrTwoFactorNotEnrolled(err) {
ctx.ServerError("UserSignIn", err)
Expand Down Expand Up @@ -846,7 +846,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *models.LoginSource, u *mod

// OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
// login the user
func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
oauth2Source := loginSource.Cfg.(*oauth2.Source)

gothUser, err := oauth2Source.Callback(request, response)
Expand Down
2 changes: 1 addition & 1 deletion services/auth/source/oauth2/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ type Source struct {
OpenIDConnectAutoDiscoveryURL string
CustomURLMapping *CustomURLMapping
IconURL string
OverrideLocalTwoFA bool

Scopes []string
RequiredClaimName string
RequiredClaimValue string
GroupClaimName string
AdminGroup string
RestrictedGroup string
SkipLocalTwoFA bool

// reference to the loginSource
loginSource *login.Source
Expand Down
2 changes: 1 addition & 1 deletion services/externalaccount/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func toExternalLoginUser(user *models.User, gothUser goth.User) (*models.ExternalLoginUser, error) {
loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
loginSource, err := login.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion services/forms/auth_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ type AuthenticationForm struct {
Oauth2EmailURL string
Oauth2IconURL string
Oauth2Tenant string
OverrideLocalTwoFA bool
Oauth2Scopes string
Oauth2RequiredClaimName string
Oauth2RequiredClaimValue string
Oauth2GroupClaimName string
Oauth2AdminGroup string
Oauth2RestrictedGroup string
SkipLocalTwoFA bool
SSPIAutoCreateUsers bool
SSPIAutoActivateUsers bool
SSPIStripDomainNames bool
Expand Down
10 changes: 2 additions & 8 deletions templates/admin/auth/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,9 @@
</div>
<div class="optional field">
<div class="ui checkbox">
<label for="override_local_two_fa"><strong>{{.i18n.Tr "admin.auths.override_local_two_fa"}}</strong></label>
<input id="override_local_two_fa" name="override_local_two_fa" type="checkbox" {{if $cfg.OverrideLocalTwoFA}}checked{{end}}>
<p class="help">{{.i18n.Tr "admin.auths.override_local_two_fa_helper"}}</p>
<input id="skip_local_two_fa" name="skip_local_two_fa" type="checkbox" {{if $cfg.SkipLocalTwoFA}}checked{{end}}>
<p class="help">{{.i18n.Tr "admin.auths.skip_local_two_fa_helper"}}</p>
</div>
</div>

<div class="oauth2_use_custom_url inline field">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.auths.oauth2_use_custom_url"}}</strong></label>
<input id="oauth2_use_custom_url" name="oauth2_use_custom_url" type="checkbox" {{if $cfg.CustomURLMapping}}checked{{end}}>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/admin/auth/source/oauth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
</div>
<div class="optional field">
<div class="ui checkbox">
<label for="override_local_two_fa"><strong>{{.i18n.Tr "admin.auths.override_local_two_fa"}}</strong></label>
<input id="override_local_two_fa" name="override_local_two_fa" type="checkbox" {{if .override_local_two_fa}}checked{{end}}>
<p class="help">{{.i18n.Tr "admin.auths.override_local_two_fa_helper"}}</p>
<label for="skip_local_two_fa"><strong>{{.i18n.Tr "admin.auths.skip_local_two_fa"}}</strong></label>
<input id="skip_local_two_fa" name="skip_local_two_fa" type="checkbox" {{if .skip_local_two_fa}}checked{{end}}>
<p class="help">{{.i18n.Tr "admin.auths.skip_local_two_fa_helper"}}</p>
</div>
</div>

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.