diff --git a/internal/auth/auth.go b/internal/auth/auth.go index cf100a3c3..5495d1e43 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -33,7 +33,7 @@ const ( deviceCodeEndpoint = "https://auth0.auth0.com/oauth/device/code" oauthTokenEndpoint = "https://auth0.auth0.com/oauth/token" // TODO(jfatta) extend the scope as we extend the CLI: - scope = "openid create:actions create:clients create:resource_servers create:connections create:hooks create:rules delete:actions delete:clients delete:connections delete:hooks delete:rules read:actions read:clients read:resource_servers read:connections read:hooks read:logs read:rules update:actions update:clients update:resource_servers update:connections update:hooks update:rules" + scope = "openid create:actions create:clients create:resource_servers create:connections create:hooks create:rules delete:actions delete:clients delete:resource_servers delete:connections delete:hooks delete:rules read:actions read:clients read:resource_servers read:connections read:hooks read:logs read:rules update:actions update:clients update:resource_servers update:connections update:hooks update:rules" audiencePath = "/api/v2/" ) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 839a31819..0781d1eb9 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -16,6 +16,7 @@ func apisCmd(cli *cli) *cobra.Command { cmd.AddCommand(listApisCmd(cli)) cmd.AddCommand(createApiCmd(cli)) cmd.AddCommand(updateApiCmd(cli)) + cmd.AddCommand(deleteApiCmd(cli)) return cmd } @@ -93,8 +94,8 @@ auth0 apis create --name myapi --identifier http://my-api func updateApiCmd(cli *cli) *cobra.Command { var flags struct { - id string - name string + id string + name string } cmd := &cobra.Command{ @@ -128,3 +129,37 @@ auth0 apis update --id id --name myapi return cmd } + +func deleteApiCmd(cli *cli) *cobra.Command { + var flags struct { + id string + } + + cmd := &cobra.Command{ + Use: "delete", + Short: "Delete an API", + Long: `Deletes an API: + +auth0 apis delete --id id +`, + RunE: func(cmd *cobra.Command, args []string) error { + manager := &management.ResourceServerManager{Management: cli.api} + + err := ansi.Spinner("Deleting API", func() error { + return manager.Delete(flags.id) + }) + + if err != nil { + return err + } + + return nil + }, + } + + cmd.Flags().StringVarP(&flags.id, "id", "i", "", "ID of the API.") + + mustRequireFlags(cmd, "id") + + return cmd +}