From 94099f3824d30cede223441387546bf700ced6f7 Mon Sep 17 00:00:00 2001 From: "Jorge L. Fatta" Date: Mon, 25 Jan 2021 17:59:36 -0300 Subject: [PATCH 1/2] feat: callbacks field --- internal/cli/clients.go | 14 +++++++++++++- internal/display/clients.go | 33 +++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/internal/cli/clients.go b/internal/cli/clients.go index 63d20ef9e..79990bef0 100644 --- a/internal/cli/clients.go +++ b/internal/cli/clients.go @@ -57,6 +57,7 @@ func clientsCreateCmd(cli *cli) *cobra.Command { appType string description string reveal bool + callbacks []string } cmd := &cobra.Command{ Use: "create", @@ -78,6 +79,7 @@ auth0 clients create --name myapp --type [native|spa|regular|m2m] Name: &flags.name, Description: &flags.description, AppType: auth0.String(apiAppTypeFor(flags.appType)), + Callbacks: apiCallbacksFor(flags.callbacks), } err := ansi.Spinner("Creating client", func() error { @@ -95,8 +97,9 @@ auth0 clients create --name myapp --type [native|spa|regular|m2m] } cmd.Flags().StringVarP(&flags.name, "name", "n", "", "Name of the client.") cmd.Flags().StringVarP(&flags.appType, "type", "t", "", "Type of the client: [native|spa|regular|m2m]") - cmd.Flags().StringVarP(&flags.description, "description", "d", "", "Description of the client.") + cmd.Flags().StringVarP(&flags.description, "description", "d", "", "A free text description of the application. Max character count is 140.") cmd.Flags().BoolVarP(&flags.reveal, "reveal", "r", false, "⚠️ Reveal the SECRET of the created client.") + cmd.Flags().StringSliceVarP(&flags.callbacks, "callbacks", "c", nil, "After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native clients, all callbacks should use protocol https://.") mustRequireFlags(cmd, "name", "type") @@ -118,3 +121,12 @@ func apiAppTypeFor(v string) string { return v } } + +func apiCallbacksFor(s []string) []interface{} { + res := make([]interface{}, len(s)) + for i, v := range s { + res[i] = v + } + return res + +} diff --git a/internal/display/clients.go b/internal/display/clients.go index 6f2ca3b47..5fc340010 100644 --- a/internal/display/clients.go +++ b/internal/display/clients.go @@ -1,6 +1,9 @@ package display import ( + "fmt" + "strings" + "github.com/auth0/auth0-cli/internal/ansi" "gopkg.in/auth0.v5" "gopkg.in/auth0.v5/management" @@ -11,22 +14,34 @@ type clientView struct { Type string ClientID string ClientSecret string + Callbacks []string revealSecret bool } func (v *clientView) AsTableHeader() []string { if v.revealSecret { - return []string{"Name", "Type", "ClientID", "Client Secret"} + return []string{"Name", "Type", "ClientID", "Client Secret", "Callbacks"} } - return []string{"Name", "Type", "ClientID"} + return []string{"Name", "Type", "ClientID", "Callbacks"} } func (v *clientView) AsTableRow() []string { if v.revealSecret { - return []string{v.Name, v.Type, ansi.Faint(v.ClientID), ansi.Italic(v.ClientSecret)} + return []string{ + v.Name, + v.Type, + ansi.Faint(v.ClientID), + ansi.Italic(v.ClientSecret), + strings.Join(v.Callbacks, ", "), + } + } + return []string{ + v.Name, + v.Type, + ansi.Faint(v.ClientID), + strings.Join(v.Callbacks, ", "), } - return []string{v.Name, v.Type, ansi.Faint(v.ClientID)} } @@ -42,6 +57,7 @@ func (r *Renderer) ClientList(clients []*management.Client) { Type: appTypeFor(c.AppType), ClientID: auth0.StringValue(c.ClientID), ClientSecret: auth0.StringValue(c.ClientSecret), + Callbacks: callbacksFor(c.Callbacks), }) } @@ -59,6 +75,7 @@ func (r *Renderer) ClientCreate(client *management.Client, revealSecrets bool) { Type: appTypeFor(client.AppType), ClientID: auth0.StringValue(client.ClientID), ClientSecret: auth0.StringValue(client.ClientSecret), + Callbacks: callbacksFor(client.Callbacks), } r.Results([]View{v}) @@ -88,3 +105,11 @@ func appTypeFor(v *string) string { return *v } } + +func callbacksFor(s []interface{}) []string { + res := make([]string, len(s)) + for i, v := range s { + res[i] = fmt.Sprintf("%s", v) + } + return res +} From e914f55aaacafe658981001141f6a24df5cce690 Mon Sep 17 00:00:00 2001 From: Cyril David Date: Mon, 25 Jan 2021 13:20:15 -0800 Subject: [PATCH 2/2] Update internal/display/clients.go --- internal/display/clients.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/display/clients.go b/internal/display/clients.go index 5fc340010..86789ef98 100644 --- a/internal/display/clients.go +++ b/internal/display/clients.go @@ -22,7 +22,7 @@ func (v *clientView) AsTableHeader() []string { if v.revealSecret { return []string{"Name", "Type", "ClientID", "Client Secret", "Callbacks"} } - return []string{"Name", "Type", "ClientID", "Callbacks"} + return []string{"Name", "Type", "Client ID", "Callbacks"} }