-
Notifications
You must be signed in to change notification settings - Fork 55
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-267: Graceful handling of access token regeneration (2/x) #547
Changes from all commits
e08f92d
0001874
abaf51e
a0a35bf
f914c25
3daf9df
8eaccd6
4f2c5df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,13 @@ auth0 login --domain <tenant-domain> --client-id <client-id> --client-secret <cl | |
return err | ||
} | ||
} else { | ||
if _, err := RunLoginAsUser(ctx, cli, false); err != nil { | ||
welcomeMessage := fmt.Sprintf( | ||
"%s\n\n%s\n\n", | ||
"✪ Welcome to the Auth0 CLI 🎊", | ||
"If you don't have an account, please create one here: https://auth0.com/signup.", | ||
) | ||
cli.renderer.Output(welcomeMessage) | ||
if _, err := RunLoginAsUser(ctx, cli); err != nil { | ||
return err | ||
} | ||
} | ||
|
@@ -85,7 +91,6 @@ auth0 login --domain <tenant-domain> --client-id <client-id> --client-secret <cl | |
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { | ||
_ = cmd.Flags().MarkHidden("tenant") | ||
_ = cmd.Flags().MarkHidden("json") | ||
_ = cmd.Flags().MarkHidden("no-input") | ||
cmd.Parent().HelpFunc()(cmd, args) | ||
}) | ||
|
||
|
@@ -94,28 +99,13 @@ auth0 login --domain <tenant-domain> --client-id <client-id> --client-secret <cl | |
|
||
// RunLoginAsUser runs the login flow guiding the user through the process | ||
// by showing the login instructions, opening the browser. | ||
// Use `expired` to run the login from other commands setup: | ||
// this will only affect the messages. | ||
func RunLoginAsUser(ctx context.Context, cli *cli, expired bool) (Tenant, error) { | ||
message := fmt.Sprintf( | ||
"%s\n\n%s\n\n", | ||
"✪ Welcome to the Auth0 CLI 🎊", | ||
"If you don't have an account, please create one here: https://auth0.com/signup.", | ||
) | ||
|
||
if expired { | ||
message = "Please sign in to re-authorize the CLI." | ||
cli.renderer.Warnf(message) | ||
} else { | ||
cli.renderer.Output(message) | ||
} | ||
Comment on lines
-99
to
-111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracting the error messaging out of the |
||
|
||
func RunLoginAsUser(ctx context.Context, cli *cli) (Tenant, error) { | ||
state, err := cli.authenticator.Start(ctx) | ||
if err != nil { | ||
return Tenant{}, fmt.Errorf("Failed to start the authentication process: %w.", err) | ||
} | ||
|
||
message = fmt.Sprintf("Your device confirmation code is: %s\n\n", ansi.Bold(state.UserCode)) | ||
message := fmt.Sprintf("Your device confirmation code is: %s\n\n", ansi.Bold(state.UserCode)) | ||
cli.renderer.Output(message) | ||
|
||
if cli.noInput { | ||
|
@@ -209,13 +199,18 @@ func RunLoginAsMachine(ctx context.Context, inputs LoginInputs, cli *cli, cmd *c | |
return err | ||
} | ||
|
||
token, err := auth.GetAccessTokenFromClientCreds(auth.ClientCredentials{ | ||
ClientID: inputs.ClientID, | ||
ClientSecret: inputs.ClientSecret, | ||
Domain: inputs.Domain, | ||
}) | ||
token, err := auth.GetAccessTokenFromClientCreds( | ||
ctx, | ||
auth.ClientCredentials{ | ||
ClientID: inputs.ClientID, | ||
ClientSecret: inputs.ClientSecret, | ||
Domain: inputs.Domain, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf( | ||
"failed to fetch access token using client credentials. \n\n"+ | ||
"Ensure that the provided client-id, client-secret and domain are correct. \n\nerror: %w\n", err) | ||
} | ||
|
||
t := Tenant{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the empty access token check here enables more specific error messaging and guidance. Further, it didn't make sense to have both cases handled here because we always attempt to regenerate the access token no matter what below.