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

refactor(auth): improve authentication flow for oauth 2.0 with local webserver #325

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GennadySpb
Copy link

@GennadySpb GennadySpb commented Feb 17, 2022

Hello there!

PR is designed to minimize the use of interactive mode for OAuth 2.0 authentication.

The base for the extension is inspired by https://github.com/youtube/api-samples/blob/master/go/oauth2.go

…webserver

Signed-off-by: Gennady Lipenkov <xgen@yandex-team.ru>
@GennadySpb
Copy link
Author

Hey @dbyron-sf ! Could your check out PR?

@dbyron-sf
Copy link
Contributor

Hey @dbyron-sf ! Could your check out PR?

I suspect @kskewes-sf is in a better position to review this.

@kskewes-sf
Copy link
Contributor

Sure, I remember the interactive cli driven flow and this looks interesting.
I need to refresh myself on spin's oauth flow and get a local setup going which I want to do after we get release 1.27.0 out. Sound okay @GennadySpb ?
There are several reports of spin CLI being broken since 1.14 so it would be good to validate before introducing new changes.
That said will do a quick pass through PR.

codeCh = make(chan string)

go http.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO: add handle of `error`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is commented but new in this PR. Can you give an example of what error is here?
Could be something for a follow up PR.


const localWebServer = "localhost:8085"

func startWebServer() (codeCh chan string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for this please? - see: https://pkg.go.dev/net/http/httptest
We can validate:

  1. code FormValue is supplied in test and plumbed through to codeCh
  2. http response recorder has correct output
  3. listener closed
  4. error FormValue (per next comment - if part of this PR).

// openURL opens a browser window to the specified location.
// This code originally appeared at:
// http://stackoverflow.com/questions/10377243/how-can-i-launch-a-process-that-is-not-a-file-in-go
func openURL(url string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a local web server or prompt is optional in the linked code and this seems quite robust. If local web server doesn't work then use the prompt. https://github.com/youtube/api-samples/blob/master/go/oauth2.go

I'm not sure what the failure modes are for the various openURL() commands, like exec hanging with no feedback. I've managed to misconfigure Linux for xdg-open more than once 😅

If an error is returned we bail out at L48 with log.Fatalf and there is no way for a user to progress unless they fix the exec issue.

I wonder if we might want to do something like:
a) fall back to prompt for code?
b) make localWebServer selectable via spin config (default enabled?) similer to https://github.com/youtube/api-samples/blob/07263305b59a7c3275bc7e925f9ce6cabf774022/go/oauth2.go#L44

WDYT?

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.

4 participants