python-xbox 0.1.0rc0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_xbox-0.1.0rc0/.gitignore +76 -0
- python_xbox-0.1.0rc0/LICENSE +19 -0
- python_xbox-0.1.0rc0/PKG-INFO +213 -0
- python_xbox-0.1.0rc0/README.md +187 -0
- python_xbox-0.1.0rc0/pyproject.toml +131 -0
- python_xbox-0.1.0rc0/xbox/webapi/__init__.py +4 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/__init__.py +0 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/client.py +166 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/language.py +70 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/__init__.py +0 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/account/__init__.py +71 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/account/models.py +11 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/achievements/__init__.py +164 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/achievements/models.py +133 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/baseprovider.py +16 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/catalog/__init__.py +88 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/catalog/const.py +15 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/catalog/models.py +428 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/cqs/__init__.py +85 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/cqs/models.py +59 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/gameclips/__init__.py +167 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/gameclips/models.py +59 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/lists/__init__.py +71 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/lists/models.py +35 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/mediahub/__init__.py +64 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/mediahub/models.py +84 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/message/__init__.py +135 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/message/models.py +96 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/people/__init__.py +193 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/people/models.py +252 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/presence/__init__.py +112 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/presence/models.py +54 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/profile/__init__.py +142 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/profile/models.py +48 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/ratelimitedprovider.py +77 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/screenshots/__init__.py +167 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/screenshots/models.py +56 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/smartglass/__init__.py +399 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/smartglass/models.py +187 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/titlehub/__init__.py +141 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/titlehub/models.py +106 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/usersearch/__init__.py +29 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/usersearch/models.py +19 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/userstats/__init__.py +166 -0
- python_xbox-0.1.0rc0/xbox/webapi/api/provider/userstats/models.py +46 -0
- python_xbox-0.1.0rc0/xbox/webapi/authentication/__init__.py +0 -0
- python_xbox-0.1.0rc0/xbox/webapi/authentication/manager.py +162 -0
- python_xbox-0.1.0rc0/xbox/webapi/authentication/models.py +163 -0
- python_xbox-0.1.0rc0/xbox/webapi/authentication/xal.py +348 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/__init__.py +0 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/exceptions.py +57 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/filetimes.py +97 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/models.py +34 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/ratelimits/__init__.py +269 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/ratelimits/models.py +23 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/request_signer.py +189 -0
- python_xbox-0.1.0rc0/xbox/webapi/common/signed_session.py +54 -0
- python_xbox-0.1.0rc0/xbox/webapi/scripts/__init__.py +15 -0
- python_xbox-0.1.0rc0/xbox/webapi/scripts/authenticate.py +159 -0
- python_xbox-0.1.0rc0/xbox/webapi/scripts/change_gamertag.py +111 -0
- python_xbox-0.1.0rc0/xbox/webapi/scripts/friends.py +80 -0
- python_xbox-0.1.0rc0/xbox/webapi/scripts/search.py +43 -0
- python_xbox-0.1.0rc0/xbox/webapi/scripts/xal.py +113 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
.env
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
|
|
29
|
+
#Virtualenv folders and files
|
|
30
|
+
Scripts
|
|
31
|
+
pyvenv.cfg
|
|
32
|
+
Lib
|
|
33
|
+
|
|
34
|
+
# PyInstaller
|
|
35
|
+
# Usually these files are written by a python script from a template
|
|
36
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
37
|
+
*.manifest
|
|
38
|
+
*.spec
|
|
39
|
+
|
|
40
|
+
# Installer logs
|
|
41
|
+
pip-log.txt
|
|
42
|
+
pip-delete-this-directory.txt
|
|
43
|
+
|
|
44
|
+
# Unit test / coverage reports
|
|
45
|
+
htmlcov/
|
|
46
|
+
.tox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
|
|
62
|
+
# Sphinx documentation
|
|
63
|
+
docs/_build/
|
|
64
|
+
|
|
65
|
+
# PyBuilder
|
|
66
|
+
target/
|
|
67
|
+
|
|
68
|
+
# Intellij
|
|
69
|
+
.idea/
|
|
70
|
+
|
|
71
|
+
# VS Code
|
|
72
|
+
.vscode/
|
|
73
|
+
|
|
74
|
+
# Node
|
|
75
|
+
node_modules
|
|
76
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2020 OpenXbox
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-xbox
|
|
3
|
+
Version: 0.1.0rc0
|
|
4
|
+
Summary: A library to authenticate with Xbox Network and use their API
|
|
5
|
+
Project-URL: Homepage, https://github.com/tr4nt0r/python-xbox
|
|
6
|
+
Author: OpenXbox
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: xbox one live api
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: appdirs
|
|
21
|
+
Requires-Dist: ecdsa
|
|
22
|
+
Requires-Dist: httpx
|
|
23
|
+
Requires-Dist: ms-cv
|
|
24
|
+
Requires-Dist: pydantic==2.*
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Xbox-WebAPI
|
|
28
|
+
|
|
29
|
+
[](https://pypi.python.org/pypi/xbox-webapi/)
|
|
30
|
+
[](http://xbox-webapi-python.readthedocs.io/en/latest/?badge=latest)
|
|
31
|
+
[](https://github.com/OpenXbox/xbox-webapi-python/actions?query=workflow%3Abuild)
|
|
32
|
+
[](https://openxbox.org/discord)
|
|
33
|
+
|
|
34
|
+
Xbox-WebAPI is a python library to authenticate with Xbox Live via your Microsoft Account and provides Xbox related Web-API.
|
|
35
|
+
|
|
36
|
+
Authentication is supported via OAuth2.
|
|
37
|
+
|
|
38
|
+
- Register a new application in [Azure AD](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade)
|
|
39
|
+
- Name your app
|
|
40
|
+
- Select "Personal Microsoft accounts only" under supported account types
|
|
41
|
+
- Add <http://localhost/auth/callback> as a Redirect URI of type "Web"
|
|
42
|
+
- Copy your Application (client) ID for later use
|
|
43
|
+
- On the App Page, navigate to "Certificates & secrets"
|
|
44
|
+
- Generate a new client secret and save for later use
|
|
45
|
+
|
|
46
|
+
## Dependencies
|
|
47
|
+
|
|
48
|
+
- Python >= 3.8
|
|
49
|
+
|
|
50
|
+
## How to use
|
|
51
|
+
|
|
52
|
+
Install
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
pip install xbox-webapi
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Authentication
|
|
59
|
+
|
|
60
|
+
**Note: You must use non child account (> 18 years old)**
|
|
61
|
+
|
|
62
|
+
Token save location: If tokenfile is not provided via cmdline, fallback of `<appdirs.user_data_dir>/tokens.json` is used as save-location
|
|
63
|
+
|
|
64
|
+
Specifically:
|
|
65
|
+
|
|
66
|
+
Windows: `C:\\Users\\<username>\\AppData\\Local\\OpenXbox\\xbox`
|
|
67
|
+
|
|
68
|
+
Mac OSX: `/Users/<username>/Library/Application Support/xbox/tokens.json`
|
|
69
|
+
|
|
70
|
+
Linux: `/home/<username>/.local/share/xbox`
|
|
71
|
+
|
|
72
|
+
For more information, see: <https://pypi.org/project/appdirs> and module: `xbox.webapi.scripts.constants`
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
xbox-authenticate --client-id <client-id> --client-secret <client-secret>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Example: Search Xbox Live via cmdline tool
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
# Search Xbox One Catalog
|
|
82
|
+
xbox-searchlive "Some game title"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
API usage
|
|
86
|
+
|
|
87
|
+
```py
|
|
88
|
+
import asyncio
|
|
89
|
+
import sys
|
|
90
|
+
|
|
91
|
+
from httpx import HTTPStatusError
|
|
92
|
+
|
|
93
|
+
from xbox.webapi.api.client import XboxLiveClient
|
|
94
|
+
from xbox.webapi.authentication.manager import AuthenticationManager
|
|
95
|
+
from xbox.webapi.authentication.models import OAuth2TokenResponse
|
|
96
|
+
from xbox.webapi.common.signed_session import SignedSession
|
|
97
|
+
from xbox.webapi.scripts import CLIENT_ID, CLIENT_SECRET, TOKENS_FILE
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
This uses the global default client identification by OpenXbox
|
|
101
|
+
You can supply your own parameters here if you are permitted to create
|
|
102
|
+
new Microsoft OAuth Apps and know what you are doing
|
|
103
|
+
"""
|
|
104
|
+
client_id = CLIENT_ID
|
|
105
|
+
client_secret = CLIENT_SECRET
|
|
106
|
+
tokens_file = TOKENS_FILE
|
|
107
|
+
|
|
108
|
+
"""
|
|
109
|
+
For doing authentication, see xbox/webapi/scripts/authenticate.py
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
async def async_main():
|
|
114
|
+
# Create a HTTP client session
|
|
115
|
+
async with SignedSession() as session:
|
|
116
|
+
"""
|
|
117
|
+
Initialize with global OAUTH parameters from above
|
|
118
|
+
"""
|
|
119
|
+
auth_mgr = AuthenticationManager(session, client_id, client_secret, "")
|
|
120
|
+
|
|
121
|
+
"""
|
|
122
|
+
Read in tokens that you received from the `xbox-authenticate`-script previously
|
|
123
|
+
See `xbox/webapi/scripts/authenticate.py`
|
|
124
|
+
"""
|
|
125
|
+
try:
|
|
126
|
+
with open(tokens_file) as f:
|
|
127
|
+
tokens = f.read()
|
|
128
|
+
# Assign gathered tokens
|
|
129
|
+
auth_mgr.oauth = OAuth2TokenResponse.model_validate_json(tokens)
|
|
130
|
+
except FileNotFoundError as e:
|
|
131
|
+
print(
|
|
132
|
+
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
|
|
133
|
+
)
|
|
134
|
+
print("Authorizing via OAUTH")
|
|
135
|
+
url = auth_mgr.generate_authorization_url()
|
|
136
|
+
print(f"Auth via URL: {url}")
|
|
137
|
+
authorization_code = input("Enter authorization code> ")
|
|
138
|
+
tokens = await auth_mgr.request_oauth_token(authorization_code)
|
|
139
|
+
auth_mgr.oauth = tokens
|
|
140
|
+
|
|
141
|
+
"""
|
|
142
|
+
Refresh tokens, just in case
|
|
143
|
+
You could also manually check the token lifetimes and just refresh them
|
|
144
|
+
if they are close to expiry
|
|
145
|
+
"""
|
|
146
|
+
try:
|
|
147
|
+
await auth_mgr.refresh_tokens()
|
|
148
|
+
except HTTPStatusError as e:
|
|
149
|
+
print(
|
|
150
|
+
f"""
|
|
151
|
+
Could not refresh tokens from {tokens_file}, err={e}\n
|
|
152
|
+
You might have to delete the tokens file and re-authenticate
|
|
153
|
+
if refresh token is expired
|
|
154
|
+
"""
|
|
155
|
+
)
|
|
156
|
+
sys.exit(-1)
|
|
157
|
+
|
|
158
|
+
# Save the refreshed/updated tokens
|
|
159
|
+
with open(tokens_file, mode="w") as f:
|
|
160
|
+
f.write(auth_mgr.oauth.json())
|
|
161
|
+
print(f"Refreshed tokens in {tokens_file}!")
|
|
162
|
+
|
|
163
|
+
"""
|
|
164
|
+
Construct the Xbox API client from AuthenticationManager instance
|
|
165
|
+
"""
|
|
166
|
+
xbl_client = XboxLiveClient(auth_mgr)
|
|
167
|
+
|
|
168
|
+
"""
|
|
169
|
+
Some example API calls
|
|
170
|
+
"""
|
|
171
|
+
# Get friendslist
|
|
172
|
+
friendslist = await xbl_client.people.get_friends_own()
|
|
173
|
+
print(f"Your friends: {friendslist}\n")
|
|
174
|
+
|
|
175
|
+
# Get presence status (by list of XUID)
|
|
176
|
+
presence = await xbl_client.presence.get_presence_batch(
|
|
177
|
+
["2533274794093122", "2533274807551369"]
|
|
178
|
+
)
|
|
179
|
+
print(f"Statuses of some random players by XUID: {presence}\n")
|
|
180
|
+
|
|
181
|
+
# Get messages
|
|
182
|
+
messages = await xbl_client.message.get_inbox()
|
|
183
|
+
print(f"Your messages: {messages}\n")
|
|
184
|
+
|
|
185
|
+
# Get profile by GT
|
|
186
|
+
profile = await xbl_client.profile.get_profile_by_gamertag("SomeGamertag")
|
|
187
|
+
print(f"Profile under SomeGamertag gamer tag: {profile}\n")
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
asyncio.run(async_main())
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Contribute
|
|
194
|
+
|
|
195
|
+
- Report bugs/suggest features
|
|
196
|
+
- Add/update docs
|
|
197
|
+
- Add additional xbox live endpoints
|
|
198
|
+
|
|
199
|
+
## Credits
|
|
200
|
+
|
|
201
|
+
This package uses parts of [Cookiecutter](https://github.com/audreyr/cookiecutter)
|
|
202
|
+
and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.
|
|
203
|
+
The authentication code is based on [joealcorn/xbox](https://github.com/joealcorn/xbox)
|
|
204
|
+
|
|
205
|
+
Informations on endpoints gathered from:
|
|
206
|
+
|
|
207
|
+
- [XboxLive REST Reference](https://docs.microsoft.com/en-us/windows/uwp/xbox-live/xbox-live-rest/atoc-xboxlivews-reference)
|
|
208
|
+
- [XboxLiveTraceAnalyzer APIMap](https://github.com/Microsoft/xbox-live-trace-analyzer/blob/master/Source/XboxLiveTraceAnalyzer.APIMap.csv)
|
|
209
|
+
- [Xbox Live Service API](https://github.com/Microsoft/xbox-live-api)
|
|
210
|
+
|
|
211
|
+
## Disclaimer
|
|
212
|
+
|
|
213
|
+
Xbox, Xbox One, Smartglass and Xbox Live are trademarks of Microsoft Corporation. Team OpenXbox is in no way endorsed by or affiliated with Microsoft Corporation, or any associated subsidiaries, logos or trademarks.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Xbox-WebAPI
|
|
2
|
+
|
|
3
|
+
[](https://pypi.python.org/pypi/xbox-webapi/)
|
|
4
|
+
[](http://xbox-webapi-python.readthedocs.io/en/latest/?badge=latest)
|
|
5
|
+
[](https://github.com/OpenXbox/xbox-webapi-python/actions?query=workflow%3Abuild)
|
|
6
|
+
[](https://openxbox.org/discord)
|
|
7
|
+
|
|
8
|
+
Xbox-WebAPI is a python library to authenticate with Xbox Live via your Microsoft Account and provides Xbox related Web-API.
|
|
9
|
+
|
|
10
|
+
Authentication is supported via OAuth2.
|
|
11
|
+
|
|
12
|
+
- Register a new application in [Azure AD](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade)
|
|
13
|
+
- Name your app
|
|
14
|
+
- Select "Personal Microsoft accounts only" under supported account types
|
|
15
|
+
- Add <http://localhost/auth/callback> as a Redirect URI of type "Web"
|
|
16
|
+
- Copy your Application (client) ID for later use
|
|
17
|
+
- On the App Page, navigate to "Certificates & secrets"
|
|
18
|
+
- Generate a new client secret and save for later use
|
|
19
|
+
|
|
20
|
+
## Dependencies
|
|
21
|
+
|
|
22
|
+
- Python >= 3.8
|
|
23
|
+
|
|
24
|
+
## How to use
|
|
25
|
+
|
|
26
|
+
Install
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
pip install xbox-webapi
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Authentication
|
|
33
|
+
|
|
34
|
+
**Note: You must use non child account (> 18 years old)**
|
|
35
|
+
|
|
36
|
+
Token save location: If tokenfile is not provided via cmdline, fallback of `<appdirs.user_data_dir>/tokens.json` is used as save-location
|
|
37
|
+
|
|
38
|
+
Specifically:
|
|
39
|
+
|
|
40
|
+
Windows: `C:\\Users\\<username>\\AppData\\Local\\OpenXbox\\xbox`
|
|
41
|
+
|
|
42
|
+
Mac OSX: `/Users/<username>/Library/Application Support/xbox/tokens.json`
|
|
43
|
+
|
|
44
|
+
Linux: `/home/<username>/.local/share/xbox`
|
|
45
|
+
|
|
46
|
+
For more information, see: <https://pypi.org/project/appdirs> and module: `xbox.webapi.scripts.constants`
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
xbox-authenticate --client-id <client-id> --client-secret <client-secret>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Example: Search Xbox Live via cmdline tool
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
# Search Xbox One Catalog
|
|
56
|
+
xbox-searchlive "Some game title"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
API usage
|
|
60
|
+
|
|
61
|
+
```py
|
|
62
|
+
import asyncio
|
|
63
|
+
import sys
|
|
64
|
+
|
|
65
|
+
from httpx import HTTPStatusError
|
|
66
|
+
|
|
67
|
+
from xbox.webapi.api.client import XboxLiveClient
|
|
68
|
+
from xbox.webapi.authentication.manager import AuthenticationManager
|
|
69
|
+
from xbox.webapi.authentication.models import OAuth2TokenResponse
|
|
70
|
+
from xbox.webapi.common.signed_session import SignedSession
|
|
71
|
+
from xbox.webapi.scripts import CLIENT_ID, CLIENT_SECRET, TOKENS_FILE
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
This uses the global default client identification by OpenXbox
|
|
75
|
+
You can supply your own parameters here if you are permitted to create
|
|
76
|
+
new Microsoft OAuth Apps and know what you are doing
|
|
77
|
+
"""
|
|
78
|
+
client_id = CLIENT_ID
|
|
79
|
+
client_secret = CLIENT_SECRET
|
|
80
|
+
tokens_file = TOKENS_FILE
|
|
81
|
+
|
|
82
|
+
"""
|
|
83
|
+
For doing authentication, see xbox/webapi/scripts/authenticate.py
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async def async_main():
|
|
88
|
+
# Create a HTTP client session
|
|
89
|
+
async with SignedSession() as session:
|
|
90
|
+
"""
|
|
91
|
+
Initialize with global OAUTH parameters from above
|
|
92
|
+
"""
|
|
93
|
+
auth_mgr = AuthenticationManager(session, client_id, client_secret, "")
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
Read in tokens that you received from the `xbox-authenticate`-script previously
|
|
97
|
+
See `xbox/webapi/scripts/authenticate.py`
|
|
98
|
+
"""
|
|
99
|
+
try:
|
|
100
|
+
with open(tokens_file) as f:
|
|
101
|
+
tokens = f.read()
|
|
102
|
+
# Assign gathered tokens
|
|
103
|
+
auth_mgr.oauth = OAuth2TokenResponse.model_validate_json(tokens)
|
|
104
|
+
except FileNotFoundError as e:
|
|
105
|
+
print(
|
|
106
|
+
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
|
|
107
|
+
)
|
|
108
|
+
print("Authorizing via OAUTH")
|
|
109
|
+
url = auth_mgr.generate_authorization_url()
|
|
110
|
+
print(f"Auth via URL: {url}")
|
|
111
|
+
authorization_code = input("Enter authorization code> ")
|
|
112
|
+
tokens = await auth_mgr.request_oauth_token(authorization_code)
|
|
113
|
+
auth_mgr.oauth = tokens
|
|
114
|
+
|
|
115
|
+
"""
|
|
116
|
+
Refresh tokens, just in case
|
|
117
|
+
You could also manually check the token lifetimes and just refresh them
|
|
118
|
+
if they are close to expiry
|
|
119
|
+
"""
|
|
120
|
+
try:
|
|
121
|
+
await auth_mgr.refresh_tokens()
|
|
122
|
+
except HTTPStatusError as e:
|
|
123
|
+
print(
|
|
124
|
+
f"""
|
|
125
|
+
Could not refresh tokens from {tokens_file}, err={e}\n
|
|
126
|
+
You might have to delete the tokens file and re-authenticate
|
|
127
|
+
if refresh token is expired
|
|
128
|
+
"""
|
|
129
|
+
)
|
|
130
|
+
sys.exit(-1)
|
|
131
|
+
|
|
132
|
+
# Save the refreshed/updated tokens
|
|
133
|
+
with open(tokens_file, mode="w") as f:
|
|
134
|
+
f.write(auth_mgr.oauth.json())
|
|
135
|
+
print(f"Refreshed tokens in {tokens_file}!")
|
|
136
|
+
|
|
137
|
+
"""
|
|
138
|
+
Construct the Xbox API client from AuthenticationManager instance
|
|
139
|
+
"""
|
|
140
|
+
xbl_client = XboxLiveClient(auth_mgr)
|
|
141
|
+
|
|
142
|
+
"""
|
|
143
|
+
Some example API calls
|
|
144
|
+
"""
|
|
145
|
+
# Get friendslist
|
|
146
|
+
friendslist = await xbl_client.people.get_friends_own()
|
|
147
|
+
print(f"Your friends: {friendslist}\n")
|
|
148
|
+
|
|
149
|
+
# Get presence status (by list of XUID)
|
|
150
|
+
presence = await xbl_client.presence.get_presence_batch(
|
|
151
|
+
["2533274794093122", "2533274807551369"]
|
|
152
|
+
)
|
|
153
|
+
print(f"Statuses of some random players by XUID: {presence}\n")
|
|
154
|
+
|
|
155
|
+
# Get messages
|
|
156
|
+
messages = await xbl_client.message.get_inbox()
|
|
157
|
+
print(f"Your messages: {messages}\n")
|
|
158
|
+
|
|
159
|
+
# Get profile by GT
|
|
160
|
+
profile = await xbl_client.profile.get_profile_by_gamertag("SomeGamertag")
|
|
161
|
+
print(f"Profile under SomeGamertag gamer tag: {profile}\n")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
asyncio.run(async_main())
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Contribute
|
|
168
|
+
|
|
169
|
+
- Report bugs/suggest features
|
|
170
|
+
- Add/update docs
|
|
171
|
+
- Add additional xbox live endpoints
|
|
172
|
+
|
|
173
|
+
## Credits
|
|
174
|
+
|
|
175
|
+
This package uses parts of [Cookiecutter](https://github.com/audreyr/cookiecutter)
|
|
176
|
+
and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.
|
|
177
|
+
The authentication code is based on [joealcorn/xbox](https://github.com/joealcorn/xbox)
|
|
178
|
+
|
|
179
|
+
Informations on endpoints gathered from:
|
|
180
|
+
|
|
181
|
+
- [XboxLive REST Reference](https://docs.microsoft.com/en-us/windows/uwp/xbox-live/xbox-live-rest/atoc-xboxlivews-reference)
|
|
182
|
+
- [XboxLiveTraceAnalyzer APIMap](https://github.com/Microsoft/xbox-live-trace-analyzer/blob/master/Source/XboxLiveTraceAnalyzer.APIMap.csv)
|
|
183
|
+
- [Xbox Live Service API](https://github.com/Microsoft/xbox-live-api)
|
|
184
|
+
|
|
185
|
+
## Disclaimer
|
|
186
|
+
|
|
187
|
+
Xbox, Xbox One, Smartglass and Xbox Live are trademarks of Microsoft Corporation. Team OpenXbox is in no way endorsed by or affiliated with Microsoft Corporation, or any associated subsidiaries, logos or trademarks.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "python-xbox"
|
|
3
|
+
description = "A library to authenticate with Xbox Network and use their API"
|
|
4
|
+
authors = [
|
|
5
|
+
{name = "OpenXbox"},
|
|
6
|
+
]
|
|
7
|
+
dependencies = [
|
|
8
|
+
"appdirs",
|
|
9
|
+
"ecdsa",
|
|
10
|
+
"httpx",
|
|
11
|
+
"ms_cv",
|
|
12
|
+
"pydantic==2.*",
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.11"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
keywords = ["xbox one live api"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 4 - Beta",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
]
|
|
29
|
+
dynamic = ["version"]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/tr4nt0r/python-xbox"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
xbox-authenticate = "xbox.webapi.scripts.authenticate:main"
|
|
36
|
+
xbox-change-gt = "xbox.webapi.scripts.change_gamertag:main"
|
|
37
|
+
xbox-friends = "xbox.webapi.scripts.friends:main"
|
|
38
|
+
xbox-searchlive = "xbox.webapi.scripts.search:main"
|
|
39
|
+
xbox-xal = "xbox.webapi.scripts.xal:main"
|
|
40
|
+
|
|
41
|
+
[tool.ruff]
|
|
42
|
+
line-length = 88
|
|
43
|
+
target-version = "py38"
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = ["E4", "E7", "E9", "F"]
|
|
47
|
+
ignore = []
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint.isort]
|
|
50
|
+
force-sort-within-sections = true
|
|
51
|
+
known-first-party = ["aiontfy"]
|
|
52
|
+
combine-as-imports = true
|
|
53
|
+
split-on-trailing-comma = false
|
|
54
|
+
|
|
55
|
+
[tool.ruff.format]
|
|
56
|
+
quote-style = "double"
|
|
57
|
+
indent-style = "space"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
[tool.bandit]
|
|
61
|
+
exclude_dirs = ["tests"]
|
|
62
|
+
tests = [
|
|
63
|
+
"B108",
|
|
64
|
+
"B306",
|
|
65
|
+
"B307",
|
|
66
|
+
"B313",
|
|
67
|
+
"B314",
|
|
68
|
+
"B315",
|
|
69
|
+
"B316",
|
|
70
|
+
"B317",
|
|
71
|
+
"B318",
|
|
72
|
+
"B319",
|
|
73
|
+
"B320",
|
|
74
|
+
"B602",
|
|
75
|
+
"B604"
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.hatch.version]
|
|
79
|
+
source = "regex_commit"
|
|
80
|
+
commit_extra_args = ["-e"]
|
|
81
|
+
path = "xbox/webapi/__init__.py"
|
|
82
|
+
|
|
83
|
+
[tool.hatch.build.targets.sdist]
|
|
84
|
+
include = [
|
|
85
|
+
"/xbox/webapi",
|
|
86
|
+
]
|
|
87
|
+
[tool.hatch.build.targets.wheel]
|
|
88
|
+
packages = ["xbox/webapi"]
|
|
89
|
+
|
|
90
|
+
[tool.hatch.envs.default]
|
|
91
|
+
python = "3.13"
|
|
92
|
+
dependencies = [
|
|
93
|
+
"appdirs==1.4.4",
|
|
94
|
+
"ecdsa==0.19.1",
|
|
95
|
+
"httpx==0.28.1",
|
|
96
|
+
"ms_cv==0.1.1",
|
|
97
|
+
"pydantic==2.12.3",
|
|
98
|
+
"pytest==8.4.2",
|
|
99
|
+
"pytest-asyncio==1.2.0",
|
|
100
|
+
"pytest-cov==7.0.0",
|
|
101
|
+
"freezegun==1.5.5",
|
|
102
|
+
"respx~=0.22",
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
[tool.hatch.envs.hatch-test]
|
|
106
|
+
parallel = true
|
|
107
|
+
extra-dependencies = [
|
|
108
|
+
"pytest-cov~=6.2",
|
|
109
|
+
"pytest-asyncio~=1.1",
|
|
110
|
+
"respx~=0.22",
|
|
111
|
+
"freezegun==1.5.5"
|
|
112
|
+
]
|
|
113
|
+
extra-args = ["--cov=xbox/webapi/", "--cov-report=term-missing", "--cov-report=xml", "-vv"]
|
|
114
|
+
|
|
115
|
+
[tool.pytest.ini_options]
|
|
116
|
+
asyncio_mode = "auto"
|
|
117
|
+
testpaths = ["tests"]
|
|
118
|
+
pythonpath = ["xbox/webapi"]
|
|
119
|
+
|
|
120
|
+
[[tool.hatch.envs.hatch-test.matrix]]
|
|
121
|
+
python = ["3.14", "3.13", "3.12", "3.11"]
|
|
122
|
+
|
|
123
|
+
[tool.hatch.envs.hatch-static-analysis]
|
|
124
|
+
dependencies = [
|
|
125
|
+
"ruff==0.14.2",
|
|
126
|
+
]
|
|
127
|
+
config-path = "none"
|
|
128
|
+
|
|
129
|
+
[build-system]
|
|
130
|
+
requires = ["hatchling", "hatch-regex-commit"]
|
|
131
|
+
build-backend = "hatchling.build"
|
|
File without changes
|