Async Yandex Passport (mobile) auth library for Music Assistant providers
Project description
ya-passport-auth
Async Yandex Passport (mobile) authentication library for Music Assistant providers.
Features
- Full token-derivation graph — QR login, x_token exchange, music_token refresh, Passport cookie refresh, Quasar CSRF, Glagol device token, account info.
- Security-first —
SecretStrredacts tokens in repr/str/format/tracebacks, blocks pickling, host allow-list, CSRF extraction, rate limiting, response size caps, log redaction. - Async-native — built on
aiohttpwithasyncio.Lock-protected rate limiter and connection management. - Strictly typed —
mypy --strictclean, PEP 561py.typedmarker.
Installation
pip install ya-passport-auth
Quick start
from ya_passport_auth import PassportClient, SecretStr
async def main():
async with PassportClient.create() as client:
# QR login
qr = await client.start_qr_login()
print(f"Scan QR: {qr.qr_url}")
creds = await client.poll_qr_until_confirmed(qr)
# Token refresh
new_music = await client.refresh_music_token(creds.x_token)
# Account info
info = await client.fetch_account_info(creds.x_token)
print(f"Logged in as {info.display_login} (uid={info.uid})")
API overview
PassportClient
| Method | Description |
|---|---|
start_qr_login() |
Begin QR login, returns QrSession |
poll_qr_until_confirmed(qr) |
Poll until scanned, returns Credentials |
complete_qr_login(qr) |
Exchange confirmed QR for tokens |
refresh_music_token(x_token) |
x_token -> music_token |
refresh_passport_cookies(x_token) |
Refresh session cookies |
get_quasar_csrf_token() |
Quasar CSRF token |
get_glagol_device_token(music_token, ...) |
Glagol device token |
fetch_account_info(x_token) |
Account metadata |
validate_x_token(x_token) |
Check if token is valid |
SecretStr
Opaque wrapper — repr() and str() return ***, pickling raises
TypeError. Access plaintext only via get_secret().
Exception hierarchy
YaPassportError
├── NetworkError
│ └── UnexpectedHostError
└── AuthFailedError
├── InvalidCredentialsError
├── CsrfExtractionError
├── RateLimitedError
├── QRPendingError
└── QRTimeoutError
Security disclaimer
This library interacts with Yandex Passport using public mobile OAuth client IDs and secrets extracted from official Yandex Android applications. These values are well-known and present in many open-source projects; they are treated here as constants, not secrets. Do not use this library for anything other than authenticating into your own Yandex account.
There is no official Yandex API for the mobile Passport flow. Endpoints, response shapes, and regex patterns may break without notice.
License
MIT. See LICENSE and NOTICE for third-party attribution.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ya_passport_auth-1.0.0.tar.gz.
File metadata
- Download URL: ya_passport_auth-1.0.0.tar.gz
- Upload date:
- Size: 40.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57ec04acf523c66405abed4dd03a68a5dc45cd0a81ce8cf0706f51b5f5d11f6e
|
|
| MD5 |
0b7d8ec60be967d62e9771e08158fecc
|
|
| BLAKE2b-256 |
71a889800739db20a0e9b10ce278c50c6f3004ac58254cf945972ddbab60ec33
|
Provenance
The following attestation bundles were made for ya_passport_auth-1.0.0.tar.gz:
Publisher:
release.yml on trudenboy/ya-passport-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ya_passport_auth-1.0.0.tar.gz -
Subject digest:
57ec04acf523c66405abed4dd03a68a5dc45cd0a81ce8cf0706f51b5f5d11f6e - Sigstore transparency entry: 1272433846
- Sigstore integration time:
-
Permalink:
trudenboy/ya-passport-auth@7c5f8a8cad5d790f1d7e612cb64c444e9b778467 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/trudenboy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7c5f8a8cad5d790f1d7e612cb64c444e9b778467 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ya_passport_auth-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ya_passport_auth-1.0.0-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1045664fd1f80b9bdb1d477ffd2ed0abdf392ae39841204e5fb447d04222ee93
|
|
| MD5 |
a5dbe2e9fa7fa598f65b14f42b92464d
|
|
| BLAKE2b-256 |
bca0b2b94b46dcb9ad03cc23fbb4ae113d5fad04a5f2022741b08c0859329eb2
|
Provenance
The following attestation bundles were made for ya_passport_auth-1.0.0-py3-none-any.whl:
Publisher:
release.yml on trudenboy/ya-passport-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ya_passport_auth-1.0.0-py3-none-any.whl -
Subject digest:
1045664fd1f80b9bdb1d477ffd2ed0abdf392ae39841204e5fb447d04222ee93 - Sigstore transparency entry: 1272433960
- Sigstore integration time:
-
Permalink:
trudenboy/ya-passport-auth@7c5f8a8cad5d790f1d7e612cb64c444e9b778467 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/trudenboy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7c5f8a8cad5d790f1d7e612cb64c444e9b778467 -
Trigger Event:
push
-
Statement type: