Skip to content

Commit bd42966

Browse files
committed
fix name
1 parent 91f5153 commit bd42966

File tree

11 files changed

+43
-41
lines changed

11 files changed

+43
-41
lines changed

cmd/admin_auth_oauth.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ func oauthCLIFlags() []cli.Flag {
8888
Usage: "Scopes to request when to authenticate against this OAuth2 source",
8989
},
9090
&cli.StringFlag{
91-
Name: "attribute-ssh-public-key",
91+
Name: "ssh-public-key-claim-name",
9292
Usage: "Claim name that provides SSH public keys",
9393
},
9494
&cli.StringFlag{
95-
Name: "attribute-full-name",
95+
Name: "full-name-claim-name",
9696
Usage: "Claim name that provides user's full name",
9797
},
9898
&cli.StringFlag{
@@ -185,8 +185,8 @@ func parseOAuth2Config(c *cli.Command) *oauth2.Source {
185185
RestrictedGroup: c.String("restricted-group"),
186186
GroupTeamMap: c.String("group-team-map"),
187187
GroupTeamMapRemoval: c.Bool("group-team-map-removal"),
188-
AttributeSSHPublicKey: c.String("attribute-ssh-public-key"),
189-
AttributeFullName: c.String("attribute-full-name"),
188+
SSHPublicKeyClaimName: c.String("ssh-public-key-claim-name"),
189+
FullNameClaimName: c.String("full-name-claim-name"),
190190
}
191191
}
192192

@@ -278,11 +278,11 @@ func (a *authService) runUpdateOauth(ctx context.Context, c *cli.Command) error
278278
if c.IsSet("group-team-map-removal") {
279279
oAuth2Config.GroupTeamMapRemoval = c.Bool("group-team-map-removal")
280280
}
281-
if c.IsSet("attribute-ssh-public-key") {
282-
oAuth2Config.AttributeSSHPublicKey = c.String("attribute-ssh-public-key")
281+
if c.IsSet("ssh-public-key-claim-name") {
282+
oAuth2Config.SSHPublicKeyClaimName = c.String("ssh-public-key-claim-name")
283283
}
284-
if c.IsSet("attribute-full-name") {
285-
oAuth2Config.AttributeFullName = c.String("attribute-full-name")
284+
if c.IsSet("full-name-claim-name") {
285+
oAuth2Config.FullNameClaimName = c.String("full-name-claim-name")
286286
}
287287

288288
// update custom URL mapping

cmd/admin_auth_oauth_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func TestAddOauth(t *testing.T) {
8888
"--restricted-group", "restricted",
8989
"--group-team-map", `{"group1": [1,2]}`,
9090
"--group-team-map-removal=true",
91-
"--attribute-ssh-public-key", "attr_ssh_pub_key",
92-
"--attribute-full-name", "attr_full_name",
91+
"--ssh-public-key-claim-name", "attr_ssh_pub_key",
92+
"--full-name-claim-name", "attr_full_name",
9393
},
9494
source: &auth_model.Source{
9595
Type: auth_model.OAuth2,
@@ -115,8 +115,8 @@ func TestAddOauth(t *testing.T) {
115115
RestrictedGroup: "restricted",
116116
GroupTeamMap: `{"group1": [1,2]}`,
117117
GroupTeamMapRemoval: true,
118-
AttributeSSHPublicKey: "attr_ssh_pub_key",
119-
AttributeFullName: "attr_full_name",
118+
SSHPublicKeyClaimName: "attr_ssh_pub_key",
119+
FullNameClaimName: "attr_full_name",
120120
},
121121
TwoFactorPolicy: "skip",
122122
},
@@ -236,8 +236,8 @@ func TestUpdateOauth(t *testing.T) {
236236
RestrictedGroup: "old_restricted",
237237
GroupTeamMap: `{"old_group1": [1,2]}`,
238238
GroupTeamMapRemoval: true,
239-
AttributeSSHPublicKey: "old_ssh_pub_key",
240-
AttributeFullName: "old_full_name",
239+
SSHPublicKeyClaimName: "old_ssh_pub_key",
240+
FullNameClaimName: "old_full_name",
241241
},
242242
TwoFactorPolicy: "",
243243
},
@@ -263,8 +263,8 @@ func TestUpdateOauth(t *testing.T) {
263263
"--restricted-group", "restricted",
264264
"--group-team-map", `{"group1": [1,2]}`,
265265
"--group-team-map-removal=false",
266-
"--attribute-ssh-public-key", "new_ssh_pub_key",
267-
"--attribute-full-name", "new_full_name",
266+
"--ssh-public-key-claim-name", "new_ssh_pub_key",
267+
"--full-name-claim-name", "new_full_name",
268268
},
269269
authSource: &auth_model.Source{
270270
ID: 1,
@@ -291,8 +291,8 @@ func TestUpdateOauth(t *testing.T) {
291291
RestrictedGroup: "restricted",
292292
GroupTeamMap: `{"group1": [1,2]}`,
293293
GroupTeamMapRemoval: false,
294-
AttributeSSHPublicKey: "new_ssh_pub_key",
295-
AttributeFullName: "new_full_name",
294+
SSHPublicKeyClaimName: "new_ssh_pub_key",
295+
FullNameClaimName: "new_full_name",
296296
},
297297
TwoFactorPolicy: "skip",
298298
},

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,6 +3252,8 @@ auths.oauth2_required_claim_name_helper = Set this name to restrict login from t
32523252
auths.oauth2_required_claim_value = Required Claim Value
32533253
auths.oauth2_required_claim_value_helper = Set this value to restrict login from this source to users with a claim with this name and value
32543254
auths.oauth2_group_claim_name = Claim name providing group names for this source. (Optional)
3255+
auths.oauth2_full_name_claim_name = Full Name Claim Name. (Optional, if set, the user's full name will always be synchronized with this claim)
3256+
auths.oauth2_ssh_public_key_claim_name = SSH Public Key Claim Name
32553257
auths.oauth2_admin_group = Group Claim value for administrator users. (Optional - requires claim name above)
32563258
auths.oauth2_restricted_group = Group Claim value for restricted users. (Optional - requires claim name above)
32573259
auths.oauth2_map_group_to_team = Map claimed groups to Organization teams. (Optional - requires claim name above)

routers/web/admin/auths.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ func parseOAuth2Config(form forms.AuthenticationForm) *oauth2.Source {
200200
GroupTeamMap: form.Oauth2GroupTeamMap,
201201
GroupTeamMapRemoval: form.Oauth2GroupTeamMapRemoval,
202202

203-
AttributeSSHPublicKey: form.Oauth2AttributeSSHPublicKey,
204-
AttributeFullName: form.Oauth2AttributeFullName,
203+
SSHPublicKeyClaimName: form.Oauth2SSHPublicKeyClaimName,
204+
FullNameClaimName: form.Oauth2FullNameClaimName,
205205
}
206206
}
207207

routers/web/auth/oauth_signin_sync.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func oauth2SignInSync(ctx *context.Context, authSource *auth.Source, u *user_mod
2828
}
2929

3030
// sync full name
31-
fullNameKey := util.IfZero(oauth2Source.AttributeFullName, "name")
31+
fullNameKey := util.IfZero(oauth2Source.FullNameClaimName, "name")
3232
fullName, _ := gothUser.RawData[fullNameKey].(string)
3333
fullName = util.IfZero(fullName, gothUser.Name)
3434

3535
// need to update if the user has no full name set
3636
shouldUpdateFullName := u.FullName == ""
3737
// force to update if the attribute is set
38-
shouldUpdateFullName = shouldUpdateFullName || oauth2Source.AttributeFullName != ""
38+
shouldUpdateFullName = shouldUpdateFullName || oauth2Source.FullNameClaimName != ""
3939
// only update if the full name is different
4040
shouldUpdateFullName = shouldUpdateFullName && u.FullName != fullName
4141
if shouldUpdateFullName {
@@ -52,7 +52,7 @@ func oauth2SignInSync(ctx *context.Context, authSource *auth.Source, u *user_mod
5252
}
5353

5454
func oauth2SyncGetSSHKeys(source *oauth2.Source, gothUser *goth.User) ([]string, error) {
55-
value, exists := gothUser.RawData[source.AttributeSSHPublicKey]
55+
value, exists := gothUser.RawData[source.SSHPublicKeyClaimName]
5656
if !exists {
5757
return []string{}, nil
5858
}
@@ -74,7 +74,7 @@ func oauth2SyncGetSSHKeys(source *oauth2.Source, gothUser *goth.User) ([]string,
7474

7575
func oauth2UpdateSSHPubIfNeed(ctx *context.Context, authSource *auth.Source, gothUser *goth.User, user *user_model.User) error {
7676
oauth2Source, _ := authSource.Cfg.(*oauth2.Source)
77-
if oauth2Source == nil || oauth2Source.AttributeSSHPublicKey == "" {
77+
if oauth2Source == nil || oauth2Source.SSHPublicKeyClaimName == "" {
7878
return nil
7979
}
8080
sshKeys, err := oauth2SyncGetSSHKeys(oauth2Source, gothUser)

services/auth/source/oauth2/source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type Source struct {
2828
GroupTeamMapRemoval bool
2929
RestrictedGroup string
3030

31-
AttributeSSHPublicKey string
32-
AttributeFullName string
31+
SSHPublicKeyClaimName string
32+
FullNameClaimName string
3333
}
3434

3535
// FromDB fills up an OAuth2Config from serialized format.

services/forms/auth_form.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ type AuthenticationForm struct {
8585
Oauth2RestrictedGroup string
8686
Oauth2GroupTeamMap string `binding:"ValidGroupTeamMap"`
8787
Oauth2GroupTeamMapRemoval bool
88-
Oauth2AttributeSSHPublicKey string
89-
Oauth2AttributeFullName string
88+
Oauth2SSHPublicKeyClaimName string
89+
Oauth2FullNameClaimName string
9090

9191
// SSPI
9292
SSPIAutoCreateUsers bool

templates/admin/auth/edit.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,12 @@
318318
<input id="oauth2_scopes" name="oauth2_scopes" value="{{if $cfg.Scopes}}{{StringUtils.Join $cfg.Scopes ","}}{{end}}">
319319
</div>
320320
<div class="field">
321-
<label>{{ctx.Locale.Tr "admin.auths.attribute_full_name"}}</label>
322-
<input name="oauth2_attribute_full_name" value="{{$cfg.AttributeFullName}}" placeholder="name">
321+
<label>{{ctx.Locale.Tr "admin.auths.oauth2_full_name_claim_name"}}</label>
322+
<input name="oauth2_full_name_claim_name" value="{{$cfg.FullNameClaimName}}" placeholder="name">
323323
</div>
324-
<div class="field oauth2_attribute_ssh_public_key">
325-
<label>{{ctx.Locale.Tr "admin.auths.attribute_ssh_public_key"}}</label>
326-
<input name="oauth2_attribute_ssh_public_key" value="{{$cfg.AttributeSSHPublicKey}}" placeholder="sshpubkey">
324+
<div class="field oauth2_ssh_public_key_claim_name">
325+
<label>{{ctx.Locale.Tr "admin.auths.oauth2_ssh_public_key_claim_name"}}</label>
326+
<input name="oauth2_ssh_public_key_claim_name" value="{{$cfg.SSHPublicKeyClaimName}}" placeholder="sshpubkey">
327327
</div>
328328
<div class="field">
329329
<label for="oauth2_required_claim_name">{{ctx.Locale.Tr "admin.auths.oauth2_required_claim_name"}}</label>

templates/admin/auth/source/oauth.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@
8181
</div>
8282

8383
<div class="field">
84-
<label>{{ctx.Locale.Tr "admin.auths.attribute_full_name"}}</label>
85-
<input name="oauth2_attribute_full_name" value="{{.attribute_fullname}}" placeholder="name">
84+
<label>{{ctx.Locale.Tr "admin.auths.oauth2_full_name_claim_name"}}</label>
85+
<input name="oauth2_full_name_claim_name" value="{{.oauth2_full_name_claim_name}}" placeholder="name">
8686
</div>
87-
<div class="field oauth2_attribute_ssh_public_key">
88-
<label>{{ctx.Locale.Tr "admin.auths.attribute_ssh_public_key"}}</label>
89-
<input name="oauth2_attribute_ssh_public_key" value="{{.attribute_ssh_public_key}}" placeholder="sshpubkey">
87+
<div class="field oauth2_ssh_public_key_claim_name">
88+
<label>{{ctx.Locale.Tr "admin.auths.oauth2_ssh_public_key_claim_name"}}</label>
89+
<input name="oauth2_ssh_public_key_claim_name" value="{{.oauth2_ssh_public_key_claim_name}}" placeholder="sshpubkey">
9090
</div>
9191
<div class="field">
9292
<label for="oauth2_required_claim_name">{{ctx.Locale.Tr "admin.auths.oauth2_required_claim_name"}}</label>

tests/integration/oauth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,8 @@ func TestSignInOauthCallbackSyncSSHKeys(t *testing.T) {
972972
oauth2Source := oauth2.Source{
973973
Provider: "openidConnect",
974974
ClientID: "test-client-id",
975-
AttributeSSHPublicKey: "sshpubkey",
976-
AttributeFullName: "name",
975+
SSHPublicKeyClaimName: "sshpubkey",
976+
FullNameClaimName: "name",
977977
OpenIDConnectAutoDiscoveryURL: mockServer.URL + "/.well-known/openid-configuration",
978978
}
979979
addOAuth2Source(t, "test-oidc-source", oauth2Source)

0 commit comments

Comments
 (0)