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

create new func to avoid the bug on issue #61 #63

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mouismail
Copy link

@mouismail mouismail commented Jun 25, 2024

This pull request primarily focuses on improving error handling and code readability in the OAuth flow. The changes include the introduction of a new function NewGitHubHost in oauth.go to parse the host URL and return an error if parsing fails. This function is then used in the files examples_test.go, oauth_device.go, and oauth_webapp.go to replace the previous method of creating a new host, improving error handling in the process.

Fixes: #62
Fixes: cli/cli#9248

oauth.go Show resolved Hide resolved
oauth.go Outdated Show resolved Hide resolved
oauth.go Show resolved Hide resolved
if err != nil {
return nil, fmt.Errorf("error parsing the hostname '%s': %w", host, err)
}
oa.Host = host
Copy link

Choose a reason for hiding this comment

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

@mouismail We weren't doing this before, can you explain the benefits of doing this now?

Copy link
Author

Choose a reason for hiding this comment

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

I believe the reason behind this was to handle various OAuth hosts, not just GHEC and
ensures that the oa.Host is dynamically assigned if it is not already set.

Copy link

Choose a reason for hiding this comment

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

I think this makes sense to me. @jtmcg anything to add?

Copy link

@BagToad BagToad left a comment

Choose a reason for hiding this comment

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

👋 Hey @mouismail. Sorry for the delays getting to this. We reviewed this and added some comments and suggestions. Let us know if we can help with anything!

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.

Introduce safe host parsing command GitHub CLI gh auth login Panic on Invalid Hostname Input
2 participants