| 417 | } |
| 418 | |
| 419 | func (c *cli) audiencePickerOptions(client *management.Client) func(ctx context.Context) (pickerOptions, error) { |
| 420 | return func(ctx context.Context) (pickerOptions, error) { |
| 421 | var opts pickerOptions |
| 422 | |
| 423 | switch client.GetAppType() { |
| 424 | case "non_interactive": |
| 425 | clientGrants, err := c.api.ClientGrant.List( |
| 426 | ctx, |
| 427 | management.PerPage(100), |
| 428 | management.Parameter("client_id", client.GetClientID()), |
| 429 | ) |
| 430 | if err != nil { |
| 431 | return nil, err |
| 432 | } |
| 433 | |
| 434 | if len(clientGrants.ClientGrants) == 0 { |
| 435 | return nil, fmt.Errorf( |
| 436 | "the %s application is not authorized to request access tokens for any APIs.\n\n"+ |
| 437 | "Run: 'auth0 apps open %s' to open the dashboard and authorize the application", |
| 438 | ansi.Bold(client.GetName()), |
| 439 | client.GetClientID(), |
| 440 | ) |
| 441 | } |
| 442 | |
| 443 | for _, grant := range clientGrants.ClientGrants { |
| 444 | resourceServer, err := c.api.ResourceServer.Read(ctx, grant.GetAudience()) |
| 445 | if err != nil { |
| 446 | return nil, err |
| 447 | } |
| 448 | |
| 449 | label := fmt.Sprintf( |
| 450 | "%s %s", |
| 451 | resourceServer.GetName(), |
| 452 | ansi.Faint(fmt.Sprintf("(%s)", resourceServer.GetIdentifier())), |
| 453 | ) |
| 454 | |
| 455 | opts = append(opts, pickerOption{ |
| 456 | label: label, |
| 457 | value: resourceServer.GetIdentifier(), |
| 458 | }) |
| 459 | } |
| 460 | default: |
| 461 | resourceServerList, err := c.api.ResourceServer.List(ctx, management.PerPage(100)) |
| 462 | if err != nil { |
| 463 | return nil, err |
| 464 | } |
| 465 | |
| 466 | for _, resourceServer := range resourceServerList.ResourceServers { |
| 467 | label := fmt.Sprintf( |
| 468 | "%s %s", |
| 469 | resourceServer.GetName(), |
| 470 | ansi.Faint(fmt.Sprintf("(%s)", resourceServer.GetIdentifier())), |
| 471 | ) |
| 472 | opts = append(opts, pickerOption{ |
| 473 | label: label, |
| 474 | value: resourceServer.GetIdentifier(), |
| 475 | }) |
| 476 | } |