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

facing issues while generating new access token using refresh token #999

Closed
mist3rGP opened this issue Mar 30, 2022 · 4 comments
Closed
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mist3rGP
Copy link

Environment details

  • OS: Win 10
  • Python version:
  • pip version:
  • google-auth version: 2.6.2

Steps to reproduce

  1. Generate access token and refresh token. Wait for token to expire. Have logic to check validity of token. Refresh token with refresh token
  2. It will throw this error: "google.auth.exceptions.RefreshError: ('invalid_scope: Some requested scopes were invalid. {invalid=[a, c, d, e, g, h, i, l, m, ., /, o, p, r, s, t, u, w, :]}', {'error': 'invalid_scope', 'error_description': 'Some requested scopes were invalid. {invalid=[a, c, d, e, g, h, i, l, m, ., /, o, p, r, s, t, u, w, :]}', 'error_uri': 'https://developers.google.com/identity/protocols/oauth2'})"

Thanks!

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Mar 31, 2022
@arithmetic1728 arithmetic1728 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 7, 2022
@arithmetic1728
Copy link
Contributor

could you provide a simple sample to repro?

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 7, 2022
@arithmetic1728 arithmetic1728 added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 7, 2022
@shivansh-nathani
Copy link

shivansh-nathani commented Apr 12, 2022

creds = None
if os.path.exists('token.pickle'):
    with open('token.pickle', 'rb') as token:
        creds = pickle.load(token)
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            'credentials.json', 'https://www.googleapis.com/auth/spreadsheets') # here enter the name of your downloaded JSON file
        creds = flow.run_local_server(port=0)
    with open('token.pickle', 'wb') as token:
        pickle.dump(creds, token)

service = build('sheets', 'v4', credentials=creds)
cred = None
if os.path.exists('token_write.pickle'):
    with open('token_write.pickle', 'rb') as token:
        cred = pickle.load(token)
if not cred or not cred.valid:
    if cred and cred.expired and cred.refresh_token:
        cred.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file('credentials.json', 'https://www.googleapis.com/auth/spreadsheets')
        cred = flow.run_local_server()
    with open('token_write.pickle', 'wb') as token:
        pickle.dump(cred, token)

Using this sample code thats present on the samples page for google sheets.
Once the creds expire and we try to generate new token with refresh token the API throws this error.

@shivansh-nathani
Copy link

Any Updates??

@sai-sunder-s
Copy link
Contributor

The scopes parameter that is passed to InstalledAppFlow.from_client_secrets_file is a Sequence.
So it should be something like this

flow = InstalledAppFlow.from_client_secrets_file(
            'credentials.json', ['https://www.googleapis.com/auth/spreadsheets'])

Please feel free to reopen the issue if this doesn't solve your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants