Skip to content

Commit

Permalink
Merge branch 'main' into dxcdt-615-goreleaser-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Christenson II authored Nov 13, 2023
2 parents ac083f2 + ad469a7 commit 55f99fb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/auth0_test_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ auth0 test login [flags]
## Flags

```
-a, --audience string The unique identifier of the target API you want to access.
-a, --audience string The unique identifier of the target API you want to access. For Machine to Machine and Regular Web Applications, only the enabled APIs will be shown within the interactive prompt.
-c, --connection-name string The connection name to test during login.
-d, --domain string One of your custom domains.
--force Skip confirmation.
Expand Down
2 changes: 1 addition & 1 deletion docs/auth0_test_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ auth0 test token [flags]
## Flags

```
-a, --audience string The unique identifier of the target API you want to access.
-a, --audience string The unique identifier of the target API you want to access. For Machine to Machine and Regular Web Applications, only the enabled APIs will be shown within the interactive prompt.
--force Skip confirmation.
--json Output in json format.
-s, --scopes strings The list of scopes you want to use.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/PuerkitoBio/rehttp v1.3.0
github.com/auth0/go-auth0 v1.2.0
github.com/auth0/go-auth0 v1.3.0
github.com/briandowns/spinner v1.23.0
github.com/charmbracelet/glamour v0.6.0
github.com/fsnotify/fsnotify v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/auth0/go-auth0 v1.2.0 h1:pZWzWCWk038jDsItwfqrbuoN37xcNHUClfPzW+rk1ok=
github.com/auth0/go-auth0 v1.2.0/go.mod h1:tLH1Qv816g3dpqituiPNN4ET+YoNtk5++68aRg+MxaA=
github.com/auth0/go-auth0 v1.3.0 h1:46bo0C6HYtsdSj4BEF4j6IaQrSAiUqehwuv+IO3qDJ0=
github.com/auth0/go-auth0 v1.3.0/go.mod h1:gm0NUM340x77a9YVZB50HUrJJkSchD9DkiqqbAl+s34=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0 h1:0NmehRCgyk5rljDQLKUO+cRJCnduDyn11+zGZIc9Z48=
github.com/aybabtme/iocontrol v0.0.0-20150809002002-ad15bcfc95a0/go.mod h1:6L7zgvqo0idzI7IO8de6ZC051AfXb5ipkIJ7bIA2tGA=
github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg=
Expand Down
78 changes: 72 additions & 6 deletions internal/cli/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
Name: "Audience",
LongForm: "audience",
ShortForm: "a",
Help: "The unique identifier of the target API you want to access.",
Help: "The unique identifier of the target API you want to access. For Machine to Machine and Regular Web Applications, only the enabled APIs will be shown within the interactive prompt.",
}

testAudienceRequired = Flag{
Expand Down Expand Up @@ -193,18 +193,20 @@ func testTokenCmd(cli *cli) *cobra.Command {
return err
}

if err := testAudience.Ask(cmd, &inputs.Audience, nil); err != nil {
if err := testAudienceRequired.Pick(
cmd,
&inputs.Audience,
cli.audiencePickerOptions(client),
); err != nil {
return err
}

appType := client.GetAppType()

cli.renderer.Infof("Domain : " + ansi.Blue(cli.tenant))
cli.renderer.Infof("Client ID : " + ansi.Bold(client.GetClientID()))
cli.renderer.Infof("Type : " + display.ApplyColorToFriendlyAppType(display.FriendlyAppType(appType)))
cli.renderer.Infof("Type : " + display.ApplyColorToFriendlyAppType(display.FriendlyAppType(client.GetAppType())))
cli.renderer.Newline()

if appType == appTypeNonInteractive {
if client.GetAppType() == appTypeNonInteractive {
tokenResponse, err := runClientCredentialsFlow(cmd.Context(), cli, client, inputs.Audience, cli.tenant)
if err != nil {
return fmt.Errorf(
Expand Down Expand Up @@ -342,6 +344,70 @@ func (c *cli) appPickerWithCreateOption(ctx context.Context) (pickerOptions, err
return enhancedOptions, nil
}

func (c *cli) audiencePickerOptions(client *management.Client) func(ctx context.Context) (pickerOptions, error) {
return func(ctx context.Context) (pickerOptions, error) {
var opts pickerOptions

switch client.GetAppType() {
case "regular_web", "non_interactive":
clientGrants, err := c.api.ClientGrant.List(
ctx,
management.PerPage(100),
management.Parameter("client_id", client.GetClientID()),
)
if err != nil {
return nil, err
}

if len(clientGrants.ClientGrants) == 0 {
return nil, fmt.Errorf(
"the %s application is not authorized to request access tokens for any APIs.\n\n"+
"Run: 'auth0 apps open %s' to open the dashboard and authorize the application.",
ansi.Bold(client.GetName()),
client.GetClientID(),
)
}

for _, grant := range clientGrants.ClientGrants {
resourceServer, err := c.api.ResourceServer.Read(ctx, grant.GetAudience())
if err != nil {
return nil, err
}

label := fmt.Sprintf(
"%s %s",
resourceServer.GetName(),
ansi.Faint(fmt.Sprintf("(%s)", resourceServer.GetIdentifier())),
)

opts = append(opts, pickerOption{
label: label,
value: resourceServer.GetIdentifier(),
})
}
default:
resourceServerList, err := c.api.ResourceServer.List(ctx, management.PerPage(100))
if err != nil {
return nil, err
}

for _, resourceServer := range resourceServerList.ResourceServers {
label := fmt.Sprintf(
"%s %s",
resourceServer.GetName(),
ansi.Faint(fmt.Sprintf("(%s)", resourceServer.GetIdentifier())),
)
opts = append(opts, pickerOption{
label: label,
value: resourceServer.GetIdentifier(),
})
}
}

return opts, nil
}
}

func checkClientIsAuthorizedForAPI(ctx context.Context, cli *cli, client *management.Client, audience string) error {
var list *management.ClientGrantList
if err := ansi.Waiting(func() (err error) {
Expand Down

0 comments on commit 55f99fb

Please sign in to comment.