Skip to content

Commit

Permalink
feat: add id parameter to create oauth2-client cli
Browse files Browse the repository at this point in the history
fixes #3724
  • Loading branch information
inigohu committed Mar 5, 2024
1 parent fcaace4 commit f3b7ed0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/cmd_create_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
flagClientAllowedCORSOrigin = "allowed-cors-origin"
flagClientAudience = "audience"
flagClientBackchannelLogoutCallback = "backchannel-logout-callback"
flagClientId = "id"
flagClientName = "name"
flagClientClientURI = "client-uri"
flagClientContact = "contact"
Expand Down
2 changes: 2 additions & 0 deletions cmd/cmd_helper_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func clientFromFlags(cmd *cobra.Command) hydra.OAuth2Client {
Audience: flagx.MustGetStringSlice(cmd, flagClientAudience),
BackchannelLogoutSessionRequired: pointerx.Bool(flagx.MustGetBool(cmd, flagClientBackChannelLogoutSessionRequired)),
BackchannelLogoutUri: pointerx.String(flagx.MustGetString(cmd, flagClientBackchannelLogoutCallback)),
ClientId: pointerx.String(flagx.MustGetString(cmd, flagClientId)),
ClientName: pointerx.String(flagx.MustGetString(cmd, flagClientName)),
ClientSecret: pointerx.String(flagx.MustGetString(cmd, flagClientSecret)),
ClientUri: pointerx.String(flagx.MustGetString(cmd, flagClientClientURI)),
Expand Down Expand Up @@ -77,6 +78,7 @@ func registerClientFlags(flags *pflag.FlagSet) {
flags.String(flagClientLogoURI, "", "A URL string that references a logo for the client")
flags.StringSlice(flagClientAllowedCORSOrigin, []string{}, "The list of URLs allowed to make CORS requests. Requires CORS_ENABLED.")
flags.String(flagClientSubjectType, "public", "A identifier algorithm. Valid values are `public` and `pairwise`.")
flags.String(flagClientId, "", "Provide the client's id.")
flags.String(flagClientSecret, "", "Provide the client's secret.")
flags.String(flagClientName, "", "The client's name.")
flags.StringSlice(flagClientPostLogoutCallback, []string{}, "List of allowed URLs to be redirected to after a logout.")
Expand Down
4 changes: 4 additions & 0 deletions cmd/cmd_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ To encrypt an auto-generated OAuth2 Client Secret, use flags ` + "`--pgp-key`" +
}

id := args[0]
if f := cmd.Flag(flagClientId); f.Changed {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "client id cannot be updated")
return cmdx.FailSilently(cmd)
}
cc := clientFromFlags(cmd)

client, _, err := m.OAuth2Api.SetOAuth2Client(context.Background(), id).OAuth2Client(cc).Execute() //nolint:bodyclose
Expand Down
8 changes: 8 additions & 0 deletions cmd/cmd_update_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ func TestUpdateClient(t *testing.T) {

snapshotx.SnapshotT(t, json.RawMessage(actual.Raw), snapshotExcludedClientFields...)
})

t.Run("case=clientID error", func(t *testing.T) {
actual := gjson.Parse(cmdx.ExecExpectedErr(t, c,
original.GetID(),
"--id", "new-id",
))
assert.Empty(t, actual)
})
}

0 comments on commit f3b7ed0

Please sign in to comment.