simon-weber / gpsoauth

A python client library for Google Play Services OAuth.
MIT License
95 stars 31 forks source link

Add support for logging in via an OAuth token #41

Closed kiwiz closed 8 months ago

kiwiz commented 2 years ago

Relates to https://github.com/simon-weber/gpsoauth/issues/37.

It appears that Google made some changes recently which breaks the standard "master login" flow. In order to fetch a token, the user has to:

  1. Visit the URL returned by the service
  2. Log into Google
  3. Extract the oauth_token cookie that is populate
  4. Plug this back into gpsooauth

Necessary changes determined from https://gitlab.com/AuroraOSS/AuroraStore/-/blob/master/app/src/main/java/com/aurora/store/util/AC2DMTask.kt#L27-43 and tested locally.

Here's some example code, if useful for docs:


def auth():
    res = gpsoauth.perform_master_login(email, password)
    if 'Token' in res:
        return res['Token']
    if res.get('Error') == 'NeedsBrowser':
        print('Please authenticate and grab the `oauth_token` cookie:", res.get('Url'))
        token = input("Token: ")
        res = gpsoauth.perform_master_login(email, token, oauth=True)
        if 'Token' in res:
            return res['Token']
        # Fall thru
    print('Error: ', res.get('Error')
emma-eva commented 2 years ago

This method is unfinished, bcz if gmail havent recovery mail or phone number then you cant access to gmail. Have to add recovery mail to confirm it then you will get token from cookie. I did it in my php code and working good. I will fix python then pull it if you interest to use python/gpsoauth.

B16f00t commented 2 years ago

I create this function and works perfectly. But I have to obtain the OAuth before with selenium. def perform_master_login_oauth( email: str, oauth_token: str, android_id: str, service: str = "ac2dm", device_country: str = "us", operator_country: str = "us", lang: str = "en", sdk_version: int = 28, proxy: MutableMapping[str, str] | None = None, ) -> dict[str, str]:

data: dict[str, int | str | bytes] = {
    "lang": lang,
    "google_play_services_version": 19629032,
    "sdk_version": sdk_version,
    "device_country": device_country,
    "Email": email,
    "service": service,
    "get_accountid": 1,
    "ACCESS_TOKEN": 1,
    "callerPkg": "com.google.android.gms",
    "add_account": 1,
    "Token": oauth_token,
    "callerSig": "38918a453d07199354f8b19af05ec6562ced5788",
 }

return _perform_auth_request(data, proxy)
imrankhalifa85 commented 2 years ago

@emma-eva can you provide your contact info I am also working on PHP code but getting a few issues.

simon-weber commented 2 years ago

I think we're good to keep the existing interface with the changes from https://github.com/simon-weber/gpsoauth/pull/42, so I'm going to close this for now.

simon-weber commented 9 months ago

https://github.com/simon-weber/gpsoauth/issues/44#issuecomment-1737878132

simon-weber commented 9 months ago

@kiwiz I don't have the bandwidth to take this change over but I can give feedback on the PR if you or someone else wants to work on it.

I think the main things are a) setting up docs for the flow and b) figuring out the interface. Maybe a separate method like exchange_token?

kiwiz commented 9 months ago

@simon-weber I've split out the logic into a separate function and added some docs to the README. There's a more thorough description here that I could reference/link if appropriate.

kiwiz commented 8 months ago

@simon-weber Feedback on this PR would be much appreciated!

jakubklos77 commented 8 months ago

I have tested it and it actually works pretty good. Using it right now.

simon-weber commented 8 months ago

Sorry for the delay -- I was traveling the past couple of weeks.

This looks good; thanks!

kiwiz commented 8 months ago

All good! Thanks for your work maintaining this library. :]