-
Notifications
You must be signed in to change notification settings - Fork 310
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
from_authorized_user_file
always returns invalid credentials
#501
Comments
from_authorized_user_file
always returns invalid/expired credentialsfrom_authorized_user_file
always returns invalid credentials
I wonder if this was intentional because the access token is usually set to expire within a short period of time? It is likely expired in this context if it were spun up again from a JSON file. |
@alvyjudy I believe the token is valid for ~1 hour. If the token is expired the refresh logic should kick in, so I don't it's harmful to use google-auth-library-python/google/auth/credentials.py Lines 69 to 76 in 772dac6
google-auth-library-python/google/auth/credentials.py Lines 106 to 125 in 772dac6
|
@busunkim96 I feel the way google-auth-library-python/google/auth/credentials.py Lines 53 to 67 in 772dac6
Since This will cause google-auth-library-python/google/auth/credentials.py Lines 69 to 76 in 772dac6
and Please correct me if I had made a mistake interpreting the code (I'm quite new here:) |
A simpler fix would be just to add a line of code to refresh the credential before returning it. I can open a PR if that's desired |
I feel that will change our "contract" with the developer. When there's a valid access token stored, users will expect no refresh until after the 3600s have passed for it. It'd be better if we take that access token verbatim and ensure all the flags are set appropriately for however much longer that token's TTL is good for. |
@wescpy I agree with what you said. It's just that currently |
That sounds much better. Was there a particular reason why it ( |
@wescpy I don't think so. I believe it was modeled closely after oauth2client, so we might have to take another look there to see if there was a reason for exclusion. |
SG. (Of course) |
I stumbled across this while working my way from the GMail Python Quickstart towards a production app. That sample app saves/loads the token to/from a local In our projects, we store all secrets in a HashiCorp Vault instance, so a non-binary, text representation is needed for persistence. As a first step towards that, I replaced the local pickle file by a local json file. When I run the app subsquently during development, the access token is still perfectly valid; there is no reason to refresh. Still, the credentials returned by Also, why would I think I can work around this for the time being by just re-adding the access token to the credentials, but from my point of view, this just feels like a bug. |
Update: The workaround for this issue is trivial, posting it here in case anyone else runs into it:
|
- The access token is always set to `None`, so the fix involves using (the access) `token` from the saved JSON credentials file. - For refresh needs, `expiry` also needs to be saved via `to_json()`. - DUMP: As `expiry` is a `datetime.datetime` object, serialize to `datetime.isoformat()` in the same [`oauth2client` format](https://github.com/googleapis/oauth2client/blob/master/oauth2client/client.py#L55) for consistency. - LOAD: Add code to restore `expiry` back to `datetime.datetime` object when imported. - LOAD: If `expiry` was unsaved, automatically set it as expired so refresh takes place. - Minor `scopes` updates - DUMP: Add property for `scopes` so `to_json()` can grab it - LOAD: `scopes` may be saved as a string instead of a JSON array (Python list), so ensure it is Sequence[str] when imported.
* This patch for </issues/501> includes the following fixes: - The access token is always set to `None`, so the fix involves using (the access) `token` from the saved JSON credentials file. - For refresh needs, `expiry` also needs to be saved via `to_json()`. - DUMP: As `expiry` is a `datetime.datetime` object, serialize to `datetime.isoformat()` in the same [`oauth2client` format](https://github.com/googleapis/oauth2client/blob/master/oauth2client/client.py#L55) for consistency. - LOAD: Add code to restore `expiry` back to `datetime.datetime` object when imported. - LOAD: If `expiry` was unsaved, automatically set it as expired so refresh takes place. - Minor `scopes` updates - DUMP: Add property for `scopes` so `to_json()` can grab it - LOAD: `scopes` may be saved as a string instead of a JSON array (Python list), so ensure it is Sequence[str] when imported.
While the PR has been merged, this isn't officially "fixed" until the next release. However, those who are being bitten by this can at least grab the latest google/oauth2/credentials.py and replace their faulty one. |
Closed by #589 |
* refactor: split 'with_quota_project' into separate base class (#561) Co-authored-by: Tres Seaver <[email protected]> * fix: dummy commit to trigger a auto release (#597) * chore: release 1.21.1 (#599) * chore: updated CHANGELOG.md [ci skip] * chore: updated setup.cfg [ci skip] * chore: updated setup.py Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: migrate signBlob to iamcredentials.googleapis.com (#600) Migrate signBlob from iam.googleapis.com to iamcredentials.googleapis.com. This API is deprecated and will be shutdown in one year. This is used google.auth.iam.Signer. Added a system_test to sanity check the implementation. * chore: release 1.21.2 (#601) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: fix expiry for `to_json()` (#589) * This patch for </issues/501> includes the following fixes: - The access token is always set to `None`, so the fix involves using (the access) `token` from the saved JSON credentials file. - For refresh needs, `expiry` also needs to be saved via `to_json()`. - DUMP: As `expiry` is a `datetime.datetime` object, serialize to `datetime.isoformat()` in the same [`oauth2client` format](https://github.com/googleapis/oauth2client/blob/master/oauth2client/client.py#L55) for consistency. - LOAD: Add code to restore `expiry` back to `datetime.datetime` object when imported. - LOAD: If `expiry` was unsaved, automatically set it as expired so refresh takes place. - Minor `scopes` updates - DUMP: Add property for `scopes` so `to_json()` can grab it - LOAD: `scopes` may be saved as a string instead of a JSON array (Python list), so ensure it is Sequence[str] when imported. * chore: add default CODEOWNERS (#609) * chore: release 1.21.3 (#607) * feat: add asyncio based auth flow (#612) * feat: asyncio http request logic and asynchronous credentials logic (#572) Co-authored-by: Anirudh Baddepudi <[email protected]> * chore: release 1.22.0 (#615) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: move aiohttp to extra as it is currently internal surface (#619) Fix #618. Removes aiohttp from required dependencies to lessen dependency tree for google-auth. This will need to be looked at again as more folks use aiohttp and once the surfaces goes to public visibility. * chore: release 1.22.1 (#620) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: remove checks for ancient versions of Cryptography (#596) Refs #595 (comment) I see no point in checking whether someone is running a version of https://github.com/pyca/cryptography/ from 2014 that doesn't even compile against modern versions of OpenSSL anymore. * chore: sync to master Syncs to master. Fixes broken unit tests in Python 3.6 and 3.7. Aligns test_identity_pool.py with test_aws.py. Co-authored-by: Bu Sun Kim <[email protected]> Co-authored-by: Tres Seaver <[email protected]> Co-authored-by: arithmetic1728 <[email protected]> Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: wesley chun <[email protected]> Co-authored-by: Christopher Wilcox <[email protected]> Co-authored-by: Anirudh Baddepudi <[email protected]> Co-authored-by: Aarni Koskela <[email protected]>
from_user_info
currently always sets the token to None. So a credential created from a JSON is always invalid and must be refreshed.google-auth-library-python/google/oauth2/credentials.py
Lines 235 to 244 in 772dac6
If a token is available,
from_user_info
should use it.info.get('token', None)
The text was updated successfully, but these errors were encountered: