pub icon indicating copy to clipboard operation
pub copied to clipboard

Cannot authorize with pub.dartlang.org on Chrome OS

Open lukef opened this issue 7 years ago • 6 comments

Dart: Dart VM version: 2.1.1 (Unknown timestamp) on "linux_x64" OS: Chrome OS (Beta Channel - 73), Linux Beta (Debian Stretch)

Running pub uploaders add <email> will fail during the authorization process because the callback will redirect to localhost to finish the authorization step on the local dev machine. Because the web browser is running on Chrome OS (natively) and the Dart server / executable is running virtualized inside Chrome OS's Linux environment, localhost is not available.

Some common ports are available / forwarded to the linux subsystem, but not all of them so the server will not be accessible.

Chrome OS does use http://penguin.linux.test:<port> as a way to access "localhost" when using non-common ports but the authorization will see this as an external redirect and disallows it.

I'm not sure if there is a way to authorize uploaders without a web browser or to some how work around this issue?

lukef avatar Feb 26 '19 22:02 lukef

It sounds like this is a general problem with authorizing against pub.dartlang.org from a system where you don't have a browser..

ie. you would have the same issue if you ssh into a server and try to do pub publish.

I suspect that supporting a flow for users without browsers is a general solution to this problem..

Note. as a work around you can sign-in with pub on a different computer an copy the ~/.pub-cache/credentials.json file.

jonasfj avatar Feb 27 '19 11:02 jonasfj

@cskau-g, says he got localhost working on his chrome book...

edit, he got it working for 8080 and 8000

jonasfj avatar Feb 27 '19 11:02 jonasfj

A possible workaround could be to support --port option, or to default to using port 8080 if nothing is listening on that port.

jonasfj avatar Feb 27 '19 11:02 jonasfj

Oh, now I remember how I did a pub authorization in an ssh session... I just did pub publish then opened the URL in a browser on my laptop, from there I was redirected to locahost:<port> to which nobody was listening, so the browser gave me an error.

I then copied the URL from the browser into a different ssh shell on the machine where pub publish was running and did curl 'localhost:<port>?code=....' by copying the URL from my browser. It's not pretty, but it works :)

jonasfj avatar Feb 27 '19 12:02 jonasfj

Indeed, after I posted it I thought the same thing. You wouldn't be able to publish from a server unless you copy the credentials.

That's an interesting workaround. I'll try it now. If all else fails I can copy the credentials.json over. Would it be safe to assume that the token in credentials.json will be refreshed close to expiration by pub? Sorry, I didn't dig into the code to look deeper?

lukef avatar Feb 27 '19 16:02 lukef

Would it be safe to assume that the token in credentials.json will be refreshed close to expiration by pub?

This is an ordinary oauth2 refresh_token, so it can refresh and create a new access_token (the refresh_token won't expire, well, Google oauth might invalidate it at some point, if you create enough of them).

jonasfj avatar Mar 04 '19 19:03 jonasfj