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

state auth signup sends the user to the signup page instead of the login page. #2749

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

mitchell-as
Copy link
Contributor

@mitchell-as mitchell-as commented Sep 11, 2023

StoryDX-2148 As a user when I use the state auth signup command I want it to automatically open the account creation page instead of the login page

The idea is to share as much of the authentication with browser logic is possible, but account for the differences in URL.

@mitchell-as mitchell-as reopened this Sep 11, 2023
@mitchell-as mitchell-as requested a review from daved September 11, 2023 23:35
@mitchell-as mitchell-as marked this pull request as ready for review September 11, 2023 23:35
daved
daved previously approved these changes Sep 13, 2023
Comment on lines 255 to 258
if signup {
baseUrl := strings.TrimPrefix(*response.VerificationURIComplete, "https://"+constants.PlatformURL)
verificationUrl = fmt.Sprintf("%s?nextRoute=%s", constants.PlatformSignupURL, url.QueryEscape(baseUrl))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I can accept this, but would feel better if the URL was parsed, modified, then used via .String(). Please see https://pkg.go.dev/net/url#Parse and the URL type it constructs for details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. It's way more verbose, but less error prone in case our constants change.

return errs.New("Invalid response: Missing verification URL.")
}

verificationUrl := *response.VerificationURIComplete
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Go uses initialisms. In this case, since U in "Url" is capitalized, the entire acronym is capitalized as URL.

@mitchell-as mitchell-as requested review from daved and MDrakos and removed request for daved September 13, 2023 18:07
Copy link
Member

@MDrakos MDrakos left a comment

Choose a reason for hiding this comment

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

Looks good to me, just one question/potential improvement.

Comment on lines +253 to +272
if signup {
// verificationURL is of the form:
// https://platform.activestate.com/authorize/device?user-code=...
// Transform it to the form:
// https://platform.activestate.com/create-account?nextRoute=%2Fauthorize%2Fdevice%3Fuser-code%3D...
parsedURL, err := url.Parse(verificationURL)
if err != nil {
return errs.Wrap(err, "Verification URL is not valid")
}

signupURL, err := url.Parse(constants.PlatformSignupURL)
if err != nil {
return errs.Wrap(err, "constants.PlatformSignupURL is not valid")
}
query := signupURL.Query()
query.Add("nextRoute", parsedURL.RequestURI())
signupURL.RawQuery = query.Encode()

verificationURL = signupURL.String()
}
Copy link
Member

Choose a reason for hiding this comment

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

Would this be more well placed in a function of its own? One function for authenticating with the browser and another for signup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because they both use the same flow (request an auth token, call the browser, listen for response). The only difference between flows is the URL, hence the "if" you're commenting on. I didn't want to duplicate any code.

@mitchell-as mitchell-as merged commit 0177619 into version/0-41-0-RC1 Sep 14, 2023
6 checks passed
@mitchell-as mitchell-as deleted the mitchell/dx-2148 branch September 14, 2023 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants