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

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

Open
magowiz opened this issue Jul 31, 2021 · 1 comment
Open
Assignees
Labels
type: question Request for information or clarification. Not an issue.

Comments

@magowiz
Copy link

magowiz commented Jul 31, 2021

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!

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Aug 2, 2021
@busunkim96 busunkim96 added type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Aug 2, 2021
@busunkim96
Copy link
Contributor

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

@busunkim96 busunkim96 self-assigned this Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants