From 2d45fc65b9c06f0e797d3d1341a3f75272805d3c Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 5 Mar 2021 22:08:24 -0300 Subject: [PATCH 1/3] Display all app parameters in single view --- internal/cli/apps.go | 4 +- internal/display/apps.go | 136 ++++++++++++++++++++++++++++----------- 2 files changed, 100 insertions(+), 40 deletions(-) diff --git a/internal/cli/apps.go b/internal/cli/apps.go index dc6d4e82d..fcdd0899b 100644 --- a/internal/cli/apps.go +++ b/internal/cli/apps.go @@ -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.") @@ -446,7 +446,7 @@ auth0 apps update --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.") diff --git a/internal/display/apps.go b/internal/display/apps.go index 797a13242..b291acfe2 100644 --- a/internal/display/apps.go +++ b/internal/display/apps.go @@ -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 { @@ -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}, } } @@ -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 { @@ -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) @@ -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)) } @@ -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. @@ -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) From 2f3ab6d14d715f8eec672e75883d95fb820a0b3c Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 5 Mar 2021 22:12:40 -0300 Subject: [PATCH 2/3] Fix test --- internal/cli/apps_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cli/apps_test.go b/internal/cli/apps_test.go index e998c6dd7..6b122ccd6 100644 --- a/internal/cli/apps_test.go +++ b/internal/cli/apps_test.go @@ -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"}, }, ) } From 32170a2e5679660fcd535f4a2cfe99a7a0ae1266 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 5 Mar 2021 22:19:00 -0300 Subject: [PATCH 3/3] Fix test --- internal/cli/apps_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cli/apps_test.go b/internal/cli/apps_test.go index 6b122ccd6..300c07c5f 100644 --- a/internal/cli/apps_test.go +++ b/internal/cli/apps_test.go @@ -51,7 +51,7 @@ func TestClientsListCmd(t *testing.T) { expectTable(t, stdout.String(), []string{"CLIENT ID", "NAME", "TYPE"}, [][]string{ - {"some-id","some-name", "generic"}, + {"some-name", "generic", "some-id"}, }, ) }