Skip to content

Commit

Permalink
Merge pull request #139 from auth0/display-entire-app-kv
Browse files Browse the repository at this point in the history
Display all app parameters in list view
  • Loading branch information
Widcket authored Mar 6, 2021
2 parents 5c5a741 + 32170a2 commit 05b5507
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 41 deletions.
4 changes: 2 additions & 2 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ auth0 apps create --name myapp --type [native|spa|regular|m2m]
cmd.Flags().StringVarP(&flags.Description, "description", "d", "", "Description of the application. Max character count is 140.")
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 apps, all callbacks should use protocol https://.")
cmd.Flags().StringSliceVarP(&flags.AllowedOrigins, "origins", "o", nil, "Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs.")
cmd.Flags().StringSliceVarP(&flags.AllowedOrigins, "web-origins", "w", nil, "Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.")
cmd.Flags().StringSliceVarP(&flags.AllowedWebOrigins, "web-origins", "w", nil, "Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.")
cmd.Flags().StringSliceVarP(&flags.AllowedLogoutURLs, "logout-urls", "l", nil, "Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.")
cmd.Flags().StringVarP(&flags.AuthMethod, "auth-method", "a", "", "Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).")
cmd.Flags().StringSliceVarP(&flags.Grants, "grants", "g", nil, "List of grant types supported for this application. Can include code, implicit, refresh-token, credentials, password, password-realm, mfa-oob, mfa-otp, mfa-recovery-code, and device-code.")
Expand Down Expand Up @@ -446,7 +446,7 @@ auth0 apps update <id> --name myapp --type [native|spa|regular|m2m]
cmd.Flags().StringVarP(&inputs.Description, "description", "d", "", "Description of the application. Max character count is 140.")
cmd.Flags().StringSliceVarP(&inputs.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 apps, all callbacks should use protocol https://.")
cmd.Flags().StringSliceVarP(&inputs.AllowedOrigins, "origins", "o", nil, "Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs.")
cmd.Flags().StringSliceVarP(&inputs.AllowedOrigins, "web-origins", "w", nil, "Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.")
cmd.Flags().StringSliceVarP(&inputs.AllowedWebOrigins, "web-origins", "w", nil, "Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.")
cmd.Flags().StringSliceVarP(&inputs.AllowedLogoutURLs, "logout-urls", "l", nil, "Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.")
cmd.Flags().StringVarP(&inputs.AuthMethod, "auth-method", "a", "", "Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).")
cmd.Flags().StringSliceVarP(&inputs.Grants, "grants", "g", nil, "List of grant types supported for this application. Can include code, implicit, refresh-token, credentials, password, password-realm, mfa-oob, mfa-otp, mfa-recovery-code, and device-code.")
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestClientsListCmd(t *testing.T) {
}

expectTable(t, stdout.String(),
[]string{"NAME", "TYPE", "CLIENT ID"},
[]string{"CLIENT ID", "NAME", "TYPE"},
[][]string{
{"some-name", "generic", "some-id"},
},
Expand Down
136 changes: 98 additions & 38 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,50 @@ const (
)

type applicationView struct {
Name string
Type string
ClientID string
ClientSecret string
Callbacks []string
revealSecret bool
Name string
Description string
Type string
ClientID string
ClientSecret string
Callbacks []string
AllowedOrigins []string
AllowedWebOrigins []string
AllowedLogoutURLs []string
AuthMethod string
Grants []string
revealSecret bool

raw interface{}
}

func (v *applicationView) AsTableHeader() []string {
if v.revealSecret {
return []string{"Name", "Type", "ClientID", "Client Secret", "Callbacks"}
return []string{
"ClientID",
"Description",
"Name",
"Type",
"Client Secret",
"Callbacks",
"Allowed Origins",
"Allowed Web Origins",
"Allowed Logout URLs",
"Token Endpoint Auth",
"Grants",
}
}
return []string{
"Client ID",
"Description",
"Name",
"Type",
"Callbacks",
"Allowed Origins",
"Allowed Web Origins",
"Allowed Logout URLs",
"Token Endpoint Auth",
"Grants",
}
return []string{"Name", "Type", "Client ID", "Callbacks"}
}

func (v *applicationView) AsTableRow() []string {
Expand All @@ -55,23 +84,37 @@ func (v *applicationView) AsTableRow() []string {

func (v *applicationView) KeyValues() [][]string {
callbacks := strings.Join(v.Callbacks, ", ")
allowedOrigins := strings.Join(v.AllowedOrigins, ", ")
allowedWebOrigins := strings.Join(v.AllowedWebOrigins, ", ")
allowedLogoutURLs := strings.Join(v.AllowedLogoutURLs, ", ")
grants := strings.Join(v.Grants, ", ")

if v.revealSecret {
return [][]string{
[]string{"CLIENT ID", ansi.Faint(v.ClientID)},
[]string{"NAME", v.Name},
[]string{"DESCRIPTION", v.Description},
[]string{"TYPE", v.Type},
[]string{"CLIENT ID", ansi.Faint(v.ClientID)},
[]string{"CLIENT SECRET", ansi.Italic(v.ClientSecret)},
[]string{"CALLBACKS", callbacks},
[]string{"ALLOWED WEB ORIGINS", allowedWebOrigins},
[]string{"ALLOWED LOGOUT URLS", allowedLogoutURLs},
[]string{"TOKEN ENDPOINT AUTH", v.AuthMethod},
[]string{"GRANTS", grants},
}

}

return [][]string{
[]string{"CLIENT ID", ansi.Faint(v.ClientID)},
[]string{"NAME", v.Name},
[]string{"DESCRIPTION", v.Description},
[]string{"TYPE", v.Type},
[]string{"CLIENT ID", ansi.Faint(v.ClientID)},
[]string{"CALLBACKS", callbacks},
[]string{"ALLOWED ORIGINS", allowedOrigins},
[]string{"ALLOWED WEB ORIGINS", allowedWebOrigins},
[]string{"ALLOWED LOGOUT URLS", allowedLogoutURLs},
[]string{"TOKEN ENDPOINT AUTH", v.AuthMethod},
[]string{"GRANTS", grants},
}
}

Expand All @@ -91,10 +134,9 @@ type applicationListView struct {

func (v *applicationListView) AsTableHeader() []string {
if v.revealSecret {
return []string{"Name", "Type", "ClientID", "Client Secret"}
return []string{"ClientID", "Name", "Type", "Client Secret"}
}
return []string{"Name", "Type", "Client ID"}

return []string{"Client ID", "Name", "Type"}
}

func (v *applicationListView) AsTableRow() []string {
Expand Down Expand Up @@ -135,13 +177,19 @@ func (r *Renderer) ApplicationShow(client *management.Client, revealSecrets bool
r.Heading(ansi.Bold(r.Tenant), "application\n")

v := &applicationView{
revealSecret: revealSecrets,
Name: auth0.StringValue(client.Name),
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: callbacksFor(client.Callbacks),
raw: client,
revealSecret: revealSecrets,
Name: auth0.StringValue(client.Name),
Description: auth0.StringValue(client.Description),
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: interfaceSliceToString(client.Callbacks),
AllowedOrigins: interfaceSliceToString(client.AllowedOrigins),
AllowedWebOrigins: interfaceSliceToString(client.WebOrigins),
AllowedLogoutURLs: interfaceSliceToString(client.AllowedLogoutURLs),
AuthMethod: auth0.StringValue(client.TokenEndpointAuthMethod),
Grants: interfaceSliceToString(client.GrantTypes),
raw: client,
}

r.Result(v)
Expand All @@ -151,16 +199,22 @@ func (r *Renderer) ApplicationCreate(client *management.Client, revealSecrets bo
r.Heading(ansi.Bold(r.Tenant), "application created\n")

v := &applicationView{
revealSecret: revealSecrets,
Name: auth0.StringValue(client.Name),
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: callbacksFor(client.Callbacks),
raw: client,
revealSecret: revealSecrets,
Name: auth0.StringValue(client.Name),
Description: auth0.StringValue(client.Description),
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: interfaceSliceToString(client.Callbacks),
AllowedOrigins: interfaceSliceToString(client.AllowedOrigins),
AllowedWebOrigins: interfaceSliceToString(client.WebOrigins),
AllowedLogoutURLs: interfaceSliceToString(client.AllowedLogoutURLs),
AuthMethod: auth0.StringValue(client.TokenEndpointAuthMethod),
Grants: interfaceSliceToString(client.GrantTypes),
raw: client,
}

r.Results([]View{v})
r.Result(v)

r.Infof("\nQuickstarts: %s", quickstartsURIFor(client.AppType))
}
Expand All @@ -169,16 +223,22 @@ func (r *Renderer) ApplicationUpdate(client *management.Client, revealSecrets bo
r.Heading(ansi.Bold(r.Tenant), "application updated\n")

v := &applicationView{
revealSecret: revealSecrets,
Name: auth0.StringValue(client.Name),
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: callbacksFor(client.Callbacks),
raw: client,
revealSecret: revealSecrets,
Name: auth0.StringValue(client.Name),
Description: auth0.StringValue(client.Description),
Type: appTypeFor(client.AppType),
ClientID: auth0.StringValue(client.ClientID),
ClientSecret: auth0.StringValue(client.ClientSecret),
Callbacks: interfaceSliceToString(client.Callbacks),
AllowedOrigins: interfaceSliceToString(client.AllowedOrigins),
AllowedWebOrigins: interfaceSliceToString(client.WebOrigins),
AllowedLogoutURLs: interfaceSliceToString(client.AllowedLogoutURLs),
AuthMethod: auth0.StringValue(client.TokenEndpointAuthMethod),
Grants: interfaceSliceToString(client.GrantTypes),
raw: client,
}

r.Results([]View{v})
r.Result(v)
}

// TODO(cyx): determine if there's a better way to filter this out.
Expand Down Expand Up @@ -221,7 +281,7 @@ func quickstartsURIFor(v *string) string {
}
}

func callbacksFor(s []interface{}) []string {
func interfaceSliceToString(s []interface{}) []string {
res := make([]string, len(s))
for i, v := range s {
res[i] = fmt.Sprintf("%s", v)
Expand Down

0 comments on commit 05b5507

Please sign in to comment.