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

Credentials.from_authorized_user_file refresh_token is missing #209

Open
PathTech opened this issue Jun 2, 2021 · 3 comments
Open

Credentials.from_authorized_user_file refresh_token is missing #209

PathTech opened this issue Jun 2, 2021 · 3 comments

Comments

@PathTech
Copy link

PathTech commented Jun 2, 2021

Expected Behavior

quickstart.py script will give me the last 10 login as described here:
https://developers.google.com/admin-sdk/reports/v1/quickstart/python

Actual Behavior

I'm trying to run the quickstart.py with a downloaded token.json for Desktop apps.

{
    "installed": {
        "client_id": "************.apps.googleusercontent.com",
        "project_id": "sentinel-314815",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "*************",
        "redirect_uris": [
            "urn:ietf:wg:oauth:2.0:oob",
            "http://localhost"
        ]
    }
}

It gives me the following erro:

$ python quickstart.py 
Traceback (most recent call last):
  File "quickstart.py", line 50, in <module>
    main()
  File "quickstart.py", line 20, in main
    creds = Credentials.from_authorized_user_file('token.json', SCOPES)
  File "/home/zfejer/.local/lib/python3.8/site-packages/google/oauth2/credentials.py", line 326, in from_authorized_user_file
    return cls.from_authorized_user_info(data, scopes)
  File "/home/zfejer/.local/lib/python3.8/site-packages/google/oauth2/credentials.py", line 277, in from_authorized_user_info
    raise ValueError(
ValueError: Authorized user info was not in the expected format, missing fields client_secret, client_id, refresh_token.

Seems like the refresh_token is missing from my token.json. I've just generated the token.json.

Steps to Reproduce the Problem

  1. follow the instruction on the page above

Specifications

  • Python version (python --version) Python 3.8.5
  • OS (Mac/Linux/Windows) Ubuntu 20.04 on WSL2 (5.4.72-microsoft-standard-WSL2)
@djpecot
Copy link

djpecot commented Jul 20, 2021

Had a similar issue when trying to handle the Sheets API. Make sure that in the InstalledAppFlow.from_client_secrets_file() function you are using the same name as the file you downloaded from GCP. I just renamed that one to credentials.json to match the code.

The sample code doesn't well explain the difference between token.json and credentials.json. credentials.json comes from the file you download from GCP, while token.json is generated from your code after referencing credentials.json

@m-nour-massri
Copy link

The refresh_token will only be provided with the first authorization from the user so any further authorization won't provide the refresh_token in the response. To solve this you can remove the app's access from the third-party apps here: https://myaccount.google.com/u/0/permissions
this will cause the next authorization to return refresh_token

@harshit3134
Copy link

The refresh_token will only be provided with the first authorization from the user so any further authorization won't provide the refresh_token in the response. To solve this you can remove the app's access from the third-party apps here: https://myaccount.google.com/u/0/permissions this will cause the next authorization to return refresh_token

thank you bro it works

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

No branches or pull requests

4 participants