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

Add support for logging in via an OAuth token #41

Merged
merged 4 commits into from
Jan 11, 2024
Merged

Add support for logging in via an OAuth token #41

merged 4 commits into from
Jan 11, 2024

Conversation

kiwiz
Copy link
Contributor

@kiwiz kiwiz commented May 20, 2022

Relates to #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
Copy link

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
Copy link

B16f00t commented May 23, 2022

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
Copy link

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

@simon-weber
Copy link
Owner

I think we're good to keep the existing interface with the changes from #42, so I'm going to close this for now.

@simon-weber
Copy link
Owner

#44 (comment)

@simon-weber
Copy link
Owner

@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
Copy link
Contributor Author

kiwiz commented Dec 28, 2023

@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
Copy link
Contributor Author

kiwiz commented Jan 10, 2024

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

@jakubklos77
Copy link

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

@simon-weber
Copy link
Owner

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

This looks good; thanks!

@kiwiz
Copy link
Contributor Author

kiwiz commented Jan 11, 2024

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

@simon-weber simon-weber merged commit 8a52124 into simon-weber:master Jan 11, 2024
2 checks passed
@kiwiz kiwiz mentioned this pull request Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants