diff --git a/internal/cli/logout.go b/internal/cli/logout.go index 988b334a8..4e6883105 100644 --- a/internal/cli/logout.go +++ b/internal/cli/logout.go @@ -12,6 +12,7 @@ func logoutCmd(cli *cli) *cobra.Command { Use: "logout", Short: "Logout of a tenant's session", Long: `auth0 logout `, + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { // NOTE(cyx): This was mostly copy/pasted from tenants // use command. Consider refactoring. diff --git a/internal/cli/quickstarts.go b/internal/cli/quickstarts.go index c5500d5ec..e5a6129f8 100644 --- a/internal/cli/quickstarts.go +++ b/internal/cli/quickstarts.go @@ -24,11 +24,12 @@ import ( // QuickStart app types and defaults const ( - qsNative = "native" - qsSpa = "spa" - qsWebApp = "webapp" - qsBackend = "backend" - _defaultURL = "http://localhost:3000" + qsNative = "native" + qsSpa = "spa" + qsWebApp = "webapp" + qsBackend = "backend" + qsDefaultURL = "http://localhost" + qspDefaultPort = 3000 ) var ( @@ -148,7 +149,7 @@ func downloadQuickstart(cli *cli) *cobra.Command { cli.renderer.Infof("Quickstart sample sucessfully downloaded at %s", target) qsType := quickstartsTypeFor(client.GetAppType()) - if err := promptDefaultURLs(cmd.Context(), cli, client, qsType); err != nil { + if err := promptDefaultURLs(cli, client, qsType, inputs.Stack); err != nil { return err } return nil @@ -325,11 +326,13 @@ func quickstartsTypeFor(v string) string { // whether the app has already added the default quickstart url to allowed url lists. // If not, it prompts the user to add the default url and updates the application // if they accept. -func promptDefaultURLs(ctx context.Context, cli *cli, client *management.Client, qsType string) error { +func promptDefaultURLs(cli *cli, client *management.Client, qsType string, qsStack string) error { + defaultURL := defaultURLFor(qsStack) + if !strings.EqualFold(qsType, qsSpa) && !strings.EqualFold(qsType, qsWebApp) { return nil } - if containsStr(client.Callbacks, _defaultURL) || containsStr(client.AllowedLogoutURLs, _defaultURL) { + if containsStr(client.Callbacks, defaultURL) || containsStr(client.AllowedLogoutURLs, defaultURL) { return nil } @@ -339,11 +342,11 @@ func promptDefaultURLs(ctx context.Context, cli *cli, client *management.Client, AllowedLogoutURLs: client.AllowedLogoutURLs, } - if confirmed := prompt.Confirm(formatURLPrompt(qsType)); confirmed { - a.Callbacks = append(a.Callbacks, _defaultURL) - a.AllowedLogoutURLs = append(a.AllowedLogoutURLs, _defaultURL) + if confirmed := prompt.Confirm(formatURLPrompt(qsType, defaultURL)); confirmed { + a.Callbacks = append(a.Callbacks, defaultURL) + a.AllowedLogoutURLs = append(a.AllowedLogoutURLs, defaultURL) if strings.EqualFold(qsType, qsSpa) { - a.WebOrigins = append(a.WebOrigins, _defaultURL) + a.WebOrigins = append(a.WebOrigins, defaultURL) } err := ansi.Spinner("Updating application", func() error { @@ -359,7 +362,7 @@ func promptDefaultURLs(ctx context.Context, cli *cli, client *management.Client, // formatURLPrompt creates the correct prompt based on app type for // asking the user if they would like to add default urls. -func formatURLPrompt(qsType string) string { +func formatURLPrompt(qsType string, url string) string { var p strings.Builder p.WriteString("\nQuickstarts use localhost, do you want to add %s to the list of allowed callback URLs") if strings.EqualFold(qsType, qsSpa) { @@ -367,5 +370,18 @@ func formatURLPrompt(qsType string) string { } else { p.WriteString(" and logout URLs?") } - return fmt.Sprintf(p.String(), _defaultURL) + return fmt.Sprintf(p.String(), url) +} + +func defaultURLFor(s string) string { + switch strings.ToLower(s) { + case "angular": // See https://github.com/auth0-samples/auth0-angular-samples/issues/225#issuecomment-806448893 + return defaultURL(qsDefaultURL, 4200) + default: + return defaultURL(qsDefaultURL, qspDefaultPort) + } } + +func defaultURL(url string, port int) string { + return fmt.Sprintf("%s:%d", url, port) +}