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

dart pub login fails to write dart/pub-credentials.json after successful authentication #3424

Closed
GroovinChip opened this issue May 13, 2022 · 5 comments · Fixed by #3442
Closed
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@GroovinChip
Copy link

Pub version: 2.17.0
Created: 2022-05-13T11:22:56.449792
FLUTTER_ROOT: /Users/groovinchip/dev/flutter
PUB_HOSTED_URL: <not set>
PUB_CACHE: "<not set>"
Command: dart pub login
Platform: macos

---- Log transcript ----
FINE: Pub 2.17.0
FINE: Loading OAuth2 credentials.
FINE: Loading OAuth2 credentials.
MSG : Pub needs your authorization to upload packages on your behalf.
    | In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A58147&code_challenge=kfQIydIn0UcWwmCZS9EwNnNXGBTbUNUZXGYeUZPd29k&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
    | Then click "Allow access".
    | 
    | Waiting for your authorization...
MSG : Authorization received, processing...
IO  : HTTP POST https://accounts.google.com/o/oauth2/token
    | content-type: application/x-www-form-urlencoded; charset=utf-8
    | user-agent: Dart pub 2.17.0
IO  : HTTP response 200 OK for POST https://accounts.google.com/o/oauth2/token
    | took 0:00:00.229868
    | cache-control: no-cache, no-store, max-age=0, must-revalidate
    | date: Fri, 13 May 2022 15:22:56 GMT
    | transfer-encoding: chunked
    | content-encoding: gzip
    | vary: Origin,X-Origin,Referer
    | content-type: application/json; charset=utf-8
    | pragma: no-cache
    | x-xss-protection: 0
    | server: scaffolding on HTTPServer2
    | alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
    | x-frame-options: SAMEORIGIN
    | x-content-type-options: nosniff
    | expires: Mon, 01 Jan 1990 00:00:00 GMT
MSG : Successfully authorized.
IO  : HTTP GET https://accounts.google.com/.well-known/openid-configuration
    | user-agent: Dart pub 2.17.0
IO  : HTTP response 200 OK for GET https://accounts.google.com/.well-known/openid-configuration
    | took 0:00:00.019982
    | last-modified: Thu, 16 Jan 2020 21:53:16 GMT
    | cache-control: public, max-age=3600
    | access-control-allow-origin: *
    | date: Fri, 13 May 2022 14:59:14 GMT
    | content-encoding: gzip
    | vary: Accept-Encoding
    | age: 1422
    | report-to: {"group":"federated-signon-mpm-access","max_age":2592000,"endpoints":[{"url":"https://csp.withgoogle.com/csp/report-to/federated-signon-mpm-access"}]}
    | content-type: application/json
    | cross-origin-opener-policy: same-origin; report-to="federated-signon-mpm-access"
    | x-xss-protection: 0
    | server: sffe
    | content-security-policy-report-only: require-trusted-types-for 'script'; report-uri https://csp.withgoogle.com/csp/federated-signon-mpm-access
    | alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
    | accept-ranges: bytes
    | content-length: 464
    | x-content-type-options: nosniff
    | expires: Fri, 13 May 2022 15:59:14 GMT
IO  : HTTP GET https://openidconnect.googleapis.com/v1/userinfo
    | authorization: <censored>
    | user-agent: Dart pub 2.17.0
IO  : HTTP response 200 OK for GET https://openidconnect.googleapis.com/v1/userinfo
    | took 0:00:00.145133
    | cache-control: no-cache, no-store, max-age=0, must-revalidate
    | date: Fri, 13 May 2022 15:22:56 GMT
    | transfer-encoding: chunked
    | content-encoding: gzip
    | vary: Origin,X-Origin,Referer
    | content-type: application/json; charset=utf-8
    | pragma: no-cache
    | x-xss-protection: 0
    | server: ESF
    | alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
    | x-frame-options: SAMEORIGIN
    | x-content-type-options: nosniff
    | expires: Mon, 01 Jan 1990 00:00:00 GMT
FINE: Saving OAuth2 credentials.
IO  : Writing 1377 characters to text file /Users/groovinchip/Library/Application Support/dart/pub-credentials.json.
ERR : type 'Null' is not a subtype of type 'String'
FINE: Exception type: _TypeError
ERR : package:pub/src/command/login.dart 50:34  LoginCommand._retrieveUserInfo.<fn>
    | ===== asynchronous gap ===========================
    | package:pub/src/command/login.dart 42:12  LoginCommand._retrieveUserInfo
    | ===== asynchronous gap ===========================
    | package:pub/src/command/login.dart 28:24  LoginCommand.runProtected
ERR : This is an unexpected error. The full log and other details are collected in:
    | 
    |     /Users/groovinchip/.pub-cache/log/pub_log.txt
    | 
    | Consider creating an issue on https://github.com/dart-lang/pub/issues/new
    | and attaching the relevant parts of that log file.
---- End log transcript ----
@sigurdm sigurdm added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 16, 2022
@sigurdm
Copy link
Contributor

sigurdm commented May 16, 2022

It seems from the transcript that the file actually got written. It was the fetching of your details in order to write "You are now logged in as $name" that failed.

@bartekpacia
Copy link

might be related/the same as #3436

@talisk
Copy link
Contributor

talisk commented May 31, 2022

I don't think that #3427 has fixed the issue.

I've applied the patch to a local copy of the code and I"m getting the following output:

Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A42157&code_challenge=cmvaULtetJ_xhL-Wz8FSFLJxo8DY5ZdgmjN-yDfGpkQ&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
Then click "Allow access".

Waiting for your authorization...
Authorization received, processing...
Successfully authorized.
You are now logged in as null
Could not retrieve your user-details.
You might have to run pub logout to delete your credentials and try again.
The symptom is that the 'name' field is not being returned by the google auth mechanism.
I've tried pub logout and then pub login with the same results.
Is there some chance that google no longer return the 'name' field in the user info response?

Reading the google documentation:
https://developers.google.com/identity/protocols/oauth2/openid-connect#server-flow

name - The user's full name, in a displayable form. Might be provided when: The request scope included the string "profile"
The ID token is returned from a token refresh. When name claims are present, you can use them to update your app's user records.

Note that this claim is never guaranteed to be present.
Note the last sentence.

Originally posted by @bsutton in #3427 (comment)

Maybe we need to make the name field nullable.

@bartekpacia
Copy link

bartekpacia commented May 31, 2022

It hasn't. I wanted to release a package last week but was unable to get dart pub login working, so I cloned dart-lang/pub and added a print(credentialsString) in code. Then I pasted that string to GitHub Actions and voila, my problem is solved, but it's such a shame that a bug like this exists.

@jonasfj
Copy link
Member

jonasfj commented May 31, 2022

I think a workaround is to use an older version of dart, as this only affects dart >= 2.17.

That said, this seems like something worth fixing soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants