Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display all app parameters in list view #139

Merged
merged 3 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions internal/cli/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ 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"},
{"some-id","some-name", "generic"},
},
)
}
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