Skip to content

Commit

Permalink
Add support for logging in via an OAuth token (#41)
Browse files Browse the repository at this point in the history
* Add support for OAuth exchange flow (for master token)

---------

Co-authored-by: Simon Weber <[email protected]>
  • Loading branch information
kiwiz and simon-weber authored Jan 11, 2024
1 parent 6b92de9 commit 8a52124
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ Many thanks to Dima Kovalenko for reverse engineering the EncryptedPasswd signat

For an explanation of recent changes, see [the changelog](https://github.com/simon-weber/gpsoauth/blob/master/CHANGELOG.md).

## Alternative flow

There is an alternative login flow if you are experiencing `BadAuthentication` errors.

1. Login to your Google account (Ex: Via https://accounts.google.com/EmbeddedSetup)
2. Obtain the value of the `oauth_token` cookie
3. Perform the token exchange:

```python
import gpsoauth

email = '[email protected]'
android_id = '0123456789abcdef'
token = '...' # insert the oauth_token here

master_response = gpsoauth.exchange_token(email, token, android_id)
master_token = master_response['Token']

auth_response = gpsoauth.perform_oauth(
email, master_token, android_id,
service='sj', app='com.google.android.music',
client_sig='...')
token = auth_response['Auth']
```

## Ports

- C\#: <https://github.com/vemacs/GPSOAuthSharp>
Expand All @@ -44,4 +69,4 @@ For an explanation of recent changes, see [the changelog](https://github.com/sim
## Contributing

See [Contributing guidelines](https://github.com/simon-weber/gpsoauth/blob/master/CONTRIBUTING.md).
This is an open-source project and all countributions are highly welcomed.
This is an open-source project and all contributions are highly welcomed.
54 changes: 54 additions & 0 deletions gpsoauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,60 @@ def perform_master_login(
return _perform_auth_request(data, proxy)


def exchange_token(
email: str,
token: str,
android_id: str,
service: str = "ac2dm",
device_country: str = "us",
operator_country: str = "us",
lang: str = "en",
sdk_version: int = 17,
proxy: MutableMapping[str, str] | None = None,
client_sig: str = "38918a453d07199354f8b19af05ec6562ced5788",
) -> dict[str, str]:
"""
Exchanges a web oauth_token for a master token.
Return a dict, eg::
{
'Auth': '...',
'Email': '[email protected]',
'GooglePlusUpgrade': '1',
'LSID': '...',
'PicasaUser': 'My Name',
'RopRevision': '1',
'RopText': ' ',
'SID': '...',
'Token': 'oauth2rt_1/...',
'firstName': 'My',
'lastName': 'Name',
'services': 'hist,mail,googleme,...'
}
"""

data: dict[str, int | str | bytes] = {
"accountType": "HOSTED_OR_GOOGLE",
"Email": email,
"has_permission": 1,
"add_account": 1,
"ACCESS_TOKEN": 1,
"Token": token,
"service": service,
"source": "android",
"androidId": android_id,
"device_country": device_country,
"operatorCountry": operator_country,
"lang": lang,
"sdk_version": sdk_version,
"client_sig": client_sig,
"callerSig": client_sig,
"droidguard_results": "dummy123",
}

return _perform_auth_request(data, proxy)


def perform_oauth(
email: str,
master_token: str,
Expand Down

0 comments on commit 8a52124

Please sign in to comment.