Skip to content

Commit a3f3e31

Browse files
authored
Fix wrong scopes caused by empty scope input (#19029) (#19145)
Backport #19029 Fix #18972 Gitea prepends requested openid scope with + after updating authentication source
1 parent ea56bdc commit a3f3e31

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

routers/web/admin/auths.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,22 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source {
181181
} else {
182182
customURLMapping = nil
183183
}
184+
var scopes []string
185+
for _, s := range strings.Split(form.Oauth2Scopes, ",") {
186+
s = strings.TrimSpace(s)
187+
if s != "" {
188+
scopes = append(scopes, s)
189+
}
190+
}
191+
184192
return &oauth2.Source{
185193
Provider: form.Oauth2Provider,
186194
ClientID: form.Oauth2Key,
187195
ClientSecret: form.Oauth2Secret,
188196
OpenIDConnectAutoDiscoveryURL: form.OpenIDConnectAutoDiscoveryURL,
189197
CustomURLMapping: customURLMapping,
190198
IconURL: form.Oauth2IconURL,
191-
Scopes: strings.Split(form.Oauth2Scopes, ","),
199+
Scopes: scopes,
192200
RequiredClaimName: form.Oauth2RequiredClaimName,
193201
RequiredClaimValue: form.Oauth2RequiredClaimValue,
194202
SkipLocalTwoFA: form.SkipLocalTwoFA,
@@ -243,6 +251,9 @@ func NewAuthSourcePost(ctx *context.Context) {
243251
ctx.Data["SSPISeparatorReplacement"] = "_"
244252
ctx.Data["SSPIDefaultLanguage"] = ""
245253

254+
// FIXME: most error path to render tplAuthNew will fail and result in 500
255+
// * template: admin/auth/new:17:68: executing "admin/auth/new" at <.type.Int>: can't evaluate field Int in type interface {}
256+
// * template: admin/auth/source/oauth:5:93: executing "admin/auth/source/oauth" at <.oauth2_provider.Name>: can't evaluate field Name in type interface {}
246257
hasTLS := false
247258
var config convert.Conversion
248259
switch auth.Type(form.Type) {
@@ -393,6 +404,7 @@ func EditAuthSourcePost(ctx *context.Context) {
393404
source.IsActive = form.IsActive
394405
source.IsSyncEnabled = form.IsSyncEnabled
395406
source.Cfg = config
407+
// FIXME: if the name conflicts, it will result in 500: Error 1062: Duplicate entry 'aa' for key 'login_source.UQE_login_source_name'
396408
if err := auth.UpdateSource(source); err != nil {
397409
if oauth2.IsErrOpenIDConnectInitialize(err) {
398410
ctx.Flash.Error(err.Error(), true)

0 commit comments

Comments
 (0)