Skip to content

unable to authenticate on android (kivy) using android client_secret #140

Closed
@magowiz

Description

@magowiz

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":

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

  1. create a new project in console.cloud.google.com with a desktop oauth credential and a android ouath credential
  2. 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!

Metadata

Metadata

Assignees

Labels

type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions