Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-340: Refactor API for test commands, fix bugs and improve DX #629

Merged
merged 26 commits into from
Jan 26, 2023

Conversation

sergiught
Copy link
Contributor

@sergiught sergiught commented Jan 24, 2023

🔧 Changes

In this PR we're aiming at offering a more cohesive experience for the auth0 test login and auth0 test token commands.

Summary of changes:

  • Renamed --connection to --connection-name in auth0 test login command (d1ac562)
  • Changed --client-id from a flag to an argument in auth0 test token command (e958077)
  • Added an option in the client ID argument picker to create a test client in case of need (b2a91c3, e958077)
  • Added checks and better error messages for when the selected client isn't authorized to get access token for the desired audience 6fa8628
  • Added checks and better error messages for when the selected client is a machine to machine type and we want to test the universal login 28fa77c

📚 References

🔬 Testing

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@sergiught sergiught force-pushed the patch/DXCDT-340-refactor-test-cmd branch from 064dc22 to 8516dc8 Compare January 24, 2023 17:02
@sergiught sergiught force-pushed the patch/DXCDT-340-refactor-test-cmd branch from 1b31632 to 127111c Compare January 24, 2023 17:08
@sergiught sergiught changed the title DXCDT-340: DXCDT-340: Refactor API for test commands, fix bugs and improve DX Jan 24, 2023
// empty type means the default client that we shouldn't display.
// Empty type means the default client that we shouldn't display.
// TODO(sergiught): We only need to exclude generic app types for
// the auth0 qs download command. Fix this in separate PR.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed in a follow up PR after this one, so that we can select Generic type apps as well across the various commands and only discard Generic types for the quickstart download command.

client, err := cli.api.Client.Read(inputs.ClientID)
if err != nil {
return fmt.Errorf("Unable to find client %s; if you specified a client, please verify it exists, otherwise re-run the command", inputs.ClientID)
if client.GetAppType() == appTypeNonInteractive {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't try to run a login for M2M app types but use the auth0 test token command instead for those.

@@ -157,46 +123,63 @@ func testLoginCmd(cli *cli) *cobra.Command {
return nil
}

if inputs.Audience != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular Web Apps could be authorized to request access tokens for a specific API so if we do pass an audience we wanna make sure the application is authorized.

cli.renderer.Infof("Domain: " + tenant.Domain)
cli.renderer.Infof("ClientID: " + inputs.ClientID)
cli.renderer.Infof("Type: " + appType + "\n")
cli.renderer.Infof("Domain : " + ansi.Blue(tenant.Domain))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a bit of color into our lives.

tokenResponse, err := runLoginFlow(
cli,
tenant,
client,
inputs.ConnectionName,
inputs.Audience, // audience is only supported for the test token command
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message that audience wasn't supported was flawed.

if isTemp {
if err := cli.api.Client.Delete(id); err != nil {
cli.renderer.Errorf("unable to remove the default test application", err.Error())
func selectClientToUseForTestsAndValidateExistence(cli *cli, cmd *cobra.Command, args []string, inputs *testCmdInputs) (*management.Client, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared logic between both test commands, we select an existing client ID or choose to create one for the test.

@sergiught sergiught marked this pull request as ready for review January 24, 2023 18:22
@sergiught sergiught requested a review from a team as a code owner January 24, 2023 18:22
@sergiught sergiught force-pushed the patch/DXCDT-340-refactor-test-cmd branch from 2b6d317 to 48daa25 Compare January 25, 2023 08:59
@sergiught sergiught self-assigned this Jan 25, 2023
internal/cli/test.go Outdated Show resolved Hide resolved
internal/cli/test.go Outdated Show resolved Hide resolved
internal/cli/test.go Outdated Show resolved Hide resolved
@sergiught sergiught requested a review from a team January 26, 2023 08:43
internal/cli/test.go Outdated Show resolved Hide resolved
internal/cli/test.go Outdated Show resolved Hide resolved
internal/cli/test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@willvedd willvedd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid DX upgrade 👍

@willvedd willvedd merged commit fc0f515 into main Jan 26, 2023
@willvedd willvedd deleted the patch/DXCDT-340-refactor-test-cmd branch January 26, 2023 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants