Skip to content

Commit e73c5fd

Browse files
authored
Fix wrong scopes caused by empty scope input (#19029)
1 parent bbce905 commit e73c5fd

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
@@ -183,14 +183,22 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source {
183183
} else {
184184
customURLMapping = nil
185185
}
186+
var scopes []string
187+
for _, s := range strings.Split(form.Oauth2Scopes, ",") {
188+
s = strings.TrimSpace(s)
189+
if s != "" {
190+
scopes = append(scopes, s)
191+
}
192+
}
193+
186194
return &oauth2.Source{
187195
Provider: form.Oauth2Provider,
188196
ClientID: form.Oauth2Key,
189197
ClientSecret: form.Oauth2Secret,
190198
OpenIDConnectAutoDiscoveryURL: form.OpenIDConnectAutoDiscoveryURL,
191199
CustomURLMapping: customURLMapping,
192200
IconURL: form.Oauth2IconURL,
193-
Scopes: strings.Split(form.Oauth2Scopes, ","),
201+
Scopes: scopes,
194202
RequiredClaimName: form.Oauth2RequiredClaimName,
195203
RequiredClaimValue: form.Oauth2RequiredClaimValue,
196204
SkipLocalTwoFA: form.SkipLocalTwoFA,
@@ -245,6 +253,9 @@ func NewAuthSourcePost(ctx *context.Context) {
245253
ctx.Data["SSPISeparatorReplacement"] = "_"
246254
ctx.Data["SSPIDefaultLanguage"] = ""
247255

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

0 commit comments

Comments
 (0)