Skip to content

Commit

Permalink
feat: callbacks field
Browse files Browse the repository at this point in the history
  • Loading branch information
jfatta committed Jan 25, 2021
1 parent 0d36b7d commit 94099f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
14 changes: 13 additions & 1 deletion internal/cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func clientsCreateCmd(cli *cli) *cobra.Command {
appType string
description string
reveal bool
callbacks []string
}
cmd := &cobra.Command{
Use: "create",
Expand All @@ -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 {
Expand All @@ -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")

Expand All @@ -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

}
33 changes: 29 additions & 4 deletions internal/display/clients.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)}

}

Expand All @@ -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),
})
}

Expand All @@ -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})
Expand Down Expand Up @@ -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
}

0 comments on commit 94099f3

Please sign in to comment.