-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for logging in via an OAuth token (#41)
* Add support for OAuth exchange flow (for master token) --------- Co-authored-by: Simon Weber <[email protected]>
- Loading branch information
1 parent
6b92de9
commit 8a52124
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|