google-auth-library-python-oauthlib
google-auth-library-python-oauthlib copied to clipboard
unable to authenticate on android (kivy) using android client_secret
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
- Search the issues already opened: https://github.com/googleapis/google-auth-library-python-oauthlib/issues
- Search StackOverflow: https://stackoverflow.com/questions/tagged/google-cloud-platform+python
If you are still having issues, please be sure to include as much information as possible:
Environment details
- OS type and version: Android 11
- Python version: 3.8.1
- pip version:
-
google-auth-oauthlib
version: 0.4.5
Steps to reproduce
- create a new project in console.cloud.google.com with a desktop oauth credential and a android ouath credential
- if using desktop credentials: it works like on my desktop environment, if using android credentials I got a KeyError that informs me that there is no 'client_secret' key and crashes, inspecting the two file it is true, in android client_secret.json provided by google there is no 'client_secret' field, while in desktop one there is.
Code example
this is the piece of code where I handle token and authorization, class attributes self.token_file and self.credentials_file are :
the token file path, the client secret file path
# example
def __token_handle__(self):
"""handles authentication token"""
# If modifying these scopes, delete the file token.json.
scopes = ['https://www.googleapis.com/auth/drive']
creds = None
if os.path.isfile(self.token_file):
creds = Credentials.from_authorized_user_file(self.token_file,
scopes)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
try:
creds.refresh(Request())
except RefreshError:
return None
else:
flow = InstalledAppFlow.from_client_secrets_file(
self.credentials_file, scopes)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open(self.token_file, 'w') as token:
token.write(creds.to_json())
return creds
# in __init__ I have this lines that calls token_handle and if creds are valid, instantiate the service:
def __init__(self):
creds = self.__token_handle__()
if creds is None:
return
# The file token.json stores the user's access and refresh tokens, and
# is
# created automatically when the authorization flow completes for the
# first
# time.
self.service = build('drive', 'v3', credentials=creds)
Stack trace
# example
# stacktrace of KeyError
07-31 14:24:39.218 16209 16335 I python : File "/xxx/.buildozer/android/app/lib/storage
/google_drive.py", line 359, in __token_handle__
07-31 14:24:39.219 16209 16335 I python : File "/xxxx/.buildozer/android/platform/build-
armeabi-v7a/build/python-installs/travel_lint/google_auth_oauthlib/flow.py", line 460, in run_local_server
07-31 14:24:39.220 16209 16335 I python : File "xxxx/projects/holiday/.buildozer/android/platform/build-
armeabi-v7a/build/python-installs/travel_lint/google_auth_oauthlib/flow.py", line 278, in fetch_token
07-31 14:24:39.221 16209 16335 I python : KeyError: 'client_secret'
07-31 14:24:39.221 16209 16335 I python : Python for android ended.
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
Hi,
I think https://stackoverflow.com/questions/41935366/what-exactly-is-the-client-secret-for-google-oauth2 addresses the issue. For Android it looks like you should follow one of these "Sign in With Google Options" instead.
https://developers.google.com/identity/sign-in/android/start https://developers.google.com/identity/one-tap/android