amazon-auth 0.1.0__tar.gz → 0.2.0__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.
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/PKG-INFO +14 -8
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/README.md +10 -6
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazon_auth.egg-info/PKG-INFO +14 -8
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazon_auth.egg-info/SOURCES.txt +0 -1
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazon_auth.egg-info/requires.txt +4 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/__init__.py +1 -1
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/cli.py +3 -83
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/constants.py +1 -3
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/session.py +2 -1
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/pyproject.toml +4 -4
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/tests/test_cli.py +30 -11
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/tests/test_constants.py +11 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/tests/test_session.py +47 -0
- amazon_auth-0.1.0/amazon_auth.egg-info/entry_points.txt +0 -2
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/LICENSE +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazon_auth.egg-info/dependency_links.txt +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazon_auth.egg-info/top_level.txt +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/conf.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/__init__.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/browser/__init__.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/browser/playwright.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/waf/__init__.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/waf/anticaptcha.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/waf/base.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/waf/capsolver.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/contrib/waf/twocaptcha.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/exception.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/forms.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/py.typed +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/region_data.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/selectors.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/amazonauth/util.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/setup.cfg +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/tests/test_conf.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/tests/test_package.py +0 -0
- {amazon_auth-0.1.0 → amazon_auth-0.2.0}/tests/test_util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: amazon-auth
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Sign in to Amazon's consumer website and reuse the session from Python.
|
|
5
5
|
Author-email: Alex Laird <contact@alexlaird.com>
|
|
6
6
|
Maintainer-email: Alex Laird <contact@alexlaird.com>
|
|
@@ -10,7 +10,6 @@ Project-URL: Sponsor, https://github.com/sponsors/alexdlaird
|
|
|
10
10
|
Project-URL: Source Code, https://github.com/alexdlaird/amazon-auth
|
|
11
11
|
Keywords: amazon,auth,sign-in,session
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
|
-
Classifier: Environment :: Console
|
|
14
13
|
Classifier: Intended Audience :: Developers
|
|
15
14
|
Classifier: Operating System :: OS Independent
|
|
16
15
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -42,6 +41,9 @@ Provides-Extra: lxml
|
|
|
42
41
|
Requires-Dist: lxml; extra == "lxml"
|
|
43
42
|
Provides-Extra: captcha
|
|
44
43
|
Requires-Dist: amazoncaptcha>=0.4; extra == "captcha"
|
|
44
|
+
Provides-Extra: integration
|
|
45
|
+
Requires-Dist: pytest-rerunfailures; extra == "integration"
|
|
46
|
+
Requires-Dist: parameterized; extra == "integration"
|
|
45
47
|
Provides-Extra: docs
|
|
46
48
|
Requires-Dist: Sphinx; extra == "docs"
|
|
47
49
|
Requires-Dist: sphinx-notfound-page; extra == "docs"
|
|
@@ -76,8 +78,8 @@ Dynamic: license-file
|
|
|
76
78
|
[](https://github.com/alexdlaird/amazon-auth/blob/main/LICENSE)
|
|
77
79
|
|
|
78
80
|
`amazon-auth` is an unofficial library that signs in to Amazon's consumer website (amazon.com and other Amazon sites)
|
|
79
|
-
and persists the session, so it can be reused from Python
|
|
80
|
-
|
|
81
|
+
and persists the session, so it can be reused from Python. It handles sign-in, OTP and MFA, challenges, and browser
|
|
82
|
+
sign-in. [`amazon-orders`](https://github.com/alexdlaird/amazon-orders) is built on it.
|
|
81
83
|
|
|
82
84
|
> **Note:** This package works by parsing Amazon's consumer-facing website. As Amazon provides no official API to use,
|
|
83
85
|
> older versions of this package may break at any time, so it's recommended that you use the latest version.
|
|
@@ -90,9 +92,9 @@ challenges, and browser sign-in. [`amazon-orders`](https://github.com/alexdlaird
|
|
|
90
92
|
pip install amazon-auth --upgrade
|
|
91
93
|
```
|
|
92
94
|
|
|
93
|
-
That's it! `amazon-auth` is now available as a package to your Python projects
|
|
95
|
+
That's it! `amazon-auth` is now available as a package to your Python projects.
|
|
94
96
|
|
|
95
|
-
If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (e.g. `==0.
|
|
97
|
+
If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (e.g. `==0.2.*`, not `==0.2.0`) to
|
|
96
98
|
ensure you always get the latest stable release.
|
|
97
99
|
|
|
98
100
|
## Basic Usage
|
|
@@ -114,8 +116,12 @@ print(response.parsed.title.text)
|
|
|
114
116
|
The most secure way to sign in is on Amazon's own page, in a browser window, so your credentials never need to be
|
|
115
117
|
stored (this requires the `browser` extra, `pip install amazon-auth[browser]`):
|
|
116
118
|
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
+
```python
|
|
120
|
+
from amazonauth.contrib.browser.playwright import PlaywrightBrowserLogin
|
|
121
|
+
from amazonauth.session import AmazonSession
|
|
122
|
+
|
|
123
|
+
amazon_session = AmazonSession()
|
|
124
|
+
PlaywrightBrowserLogin(amazon_session).login()
|
|
119
125
|
```
|
|
120
126
|
|
|
121
127
|
The session is persisted, so `AmazonSession().login()` reuses it without credentials.
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
[](https://github.com/alexdlaird/amazon-auth/blob/main/LICENSE)
|
|
9
9
|
|
|
10
10
|
`amazon-auth` is an unofficial library that signs in to Amazon's consumer website (amazon.com and other Amazon sites)
|
|
11
|
-
and persists the session, so it can be reused from Python
|
|
12
|
-
|
|
11
|
+
and persists the session, so it can be reused from Python. It handles sign-in, OTP and MFA, challenges, and browser
|
|
12
|
+
sign-in. [`amazon-orders`](https://github.com/alexdlaird/amazon-orders) is built on it.
|
|
13
13
|
|
|
14
14
|
> **Note:** This package works by parsing Amazon's consumer-facing website. As Amazon provides no official API to use,
|
|
15
15
|
> older versions of this package may break at any time, so it's recommended that you use the latest version.
|
|
@@ -22,9 +22,9 @@ challenges, and browser sign-in. [`amazon-orders`](https://github.com/alexdlaird
|
|
|
22
22
|
pip install amazon-auth --upgrade
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
That's it! `amazon-auth` is now available as a package to your Python projects
|
|
25
|
+
That's it! `amazon-auth` is now available as a package to your Python projects.
|
|
26
26
|
|
|
27
|
-
If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (e.g. `==0.
|
|
27
|
+
If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (e.g. `==0.2.*`, not `==0.2.0`) to
|
|
28
28
|
ensure you always get the latest stable release.
|
|
29
29
|
|
|
30
30
|
## Basic Usage
|
|
@@ -46,8 +46,12 @@ print(response.parsed.title.text)
|
|
|
46
46
|
The most secure way to sign in is on Amazon's own page, in a browser window, so your credentials never need to be
|
|
47
47
|
stored (this requires the `browser` extra, `pip install amazon-auth[browser]`):
|
|
48
48
|
|
|
49
|
-
```
|
|
50
|
-
|
|
49
|
+
```python
|
|
50
|
+
from amazonauth.contrib.browser.playwright import PlaywrightBrowserLogin
|
|
51
|
+
from amazonauth.session import AmazonSession
|
|
52
|
+
|
|
53
|
+
amazon_session = AmazonSession()
|
|
54
|
+
PlaywrightBrowserLogin(amazon_session).login()
|
|
51
55
|
```
|
|
52
56
|
|
|
53
57
|
The session is persisted, so `AmazonSession().login()` reuses it without credentials.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: amazon-auth
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Sign in to Amazon's consumer website and reuse the session from Python.
|
|
5
5
|
Author-email: Alex Laird <contact@alexlaird.com>
|
|
6
6
|
Maintainer-email: Alex Laird <contact@alexlaird.com>
|
|
@@ -10,7 +10,6 @@ Project-URL: Sponsor, https://github.com/sponsors/alexdlaird
|
|
|
10
10
|
Project-URL: Source Code, https://github.com/alexdlaird/amazon-auth
|
|
11
11
|
Keywords: amazon,auth,sign-in,session
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
|
-
Classifier: Environment :: Console
|
|
14
13
|
Classifier: Intended Audience :: Developers
|
|
15
14
|
Classifier: Operating System :: OS Independent
|
|
16
15
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -42,6 +41,9 @@ Provides-Extra: lxml
|
|
|
42
41
|
Requires-Dist: lxml; extra == "lxml"
|
|
43
42
|
Provides-Extra: captcha
|
|
44
43
|
Requires-Dist: amazoncaptcha>=0.4; extra == "captcha"
|
|
44
|
+
Provides-Extra: integration
|
|
45
|
+
Requires-Dist: pytest-rerunfailures; extra == "integration"
|
|
46
|
+
Requires-Dist: parameterized; extra == "integration"
|
|
45
47
|
Provides-Extra: docs
|
|
46
48
|
Requires-Dist: Sphinx; extra == "docs"
|
|
47
49
|
Requires-Dist: sphinx-notfound-page; extra == "docs"
|
|
@@ -76,8 +78,8 @@ Dynamic: license-file
|
|
|
76
78
|
[](https://github.com/alexdlaird/amazon-auth/blob/main/LICENSE)
|
|
77
79
|
|
|
78
80
|
`amazon-auth` is an unofficial library that signs in to Amazon's consumer website (amazon.com and other Amazon sites)
|
|
79
|
-
and persists the session, so it can be reused from Python
|
|
80
|
-
|
|
81
|
+
and persists the session, so it can be reused from Python. It handles sign-in, OTP and MFA, challenges, and browser
|
|
82
|
+
sign-in. [`amazon-orders`](https://github.com/alexdlaird/amazon-orders) is built on it.
|
|
81
83
|
|
|
82
84
|
> **Note:** This package works by parsing Amazon's consumer-facing website. As Amazon provides no official API to use,
|
|
83
85
|
> older versions of this package may break at any time, so it's recommended that you use the latest version.
|
|
@@ -90,9 +92,9 @@ challenges, and browser sign-in. [`amazon-orders`](https://github.com/alexdlaird
|
|
|
90
92
|
pip install amazon-auth --upgrade
|
|
91
93
|
```
|
|
92
94
|
|
|
93
|
-
That's it! `amazon-auth` is now available as a package to your Python projects
|
|
95
|
+
That's it! `amazon-auth` is now available as a package to your Python projects.
|
|
94
96
|
|
|
95
|
-
If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (e.g. `==0.
|
|
97
|
+
If pinning, be sure to use a wildcard for the [minor version](https://semver.org/) (e.g. `==0.2.*`, not `==0.2.0`) to
|
|
96
98
|
ensure you always get the latest stable release.
|
|
97
99
|
|
|
98
100
|
## Basic Usage
|
|
@@ -114,8 +116,12 @@ print(response.parsed.title.text)
|
|
|
114
116
|
The most secure way to sign in is on Amazon's own page, in a browser window, so your credentials never need to be
|
|
115
117
|
stored (this requires the `browser` extra, `pip install amazon-auth[browser]`):
|
|
116
118
|
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
+
```python
|
|
120
|
+
from amazonauth.contrib.browser.playwright import PlaywrightBrowserLogin
|
|
121
|
+
from amazonauth.session import AmazonSession
|
|
122
|
+
|
|
123
|
+
amazon_session = AmazonSession()
|
|
124
|
+
PlaywrightBrowserLogin(amazon_session).login()
|
|
119
125
|
```
|
|
120
126
|
|
|
121
127
|
The session is persisted, so `AmazonSession().login()` reuses it without credentials.
|
|
@@ -2,15 +2,12 @@ __copyright__ = "Copyright (c) 2024-2025 Alex Laird"
|
|
|
2
2
|
__license__ = "MIT"
|
|
3
3
|
|
|
4
4
|
import logging
|
|
5
|
-
import platform
|
|
6
5
|
import sys
|
|
7
6
|
from typing import Any, List, Optional
|
|
8
7
|
|
|
9
8
|
import click
|
|
10
9
|
from click.core import Context
|
|
11
10
|
|
|
12
|
-
from amazonauth import __version__
|
|
13
|
-
from amazonauth.conf import AmazonAuthConfig
|
|
14
11
|
from amazonauth.contrib.browser.playwright import PlaywrightBrowserLauncher, PlaywrightBrowserLogin
|
|
15
12
|
from amazonauth.exception import AmazonAuthBrowserNotInstalledError, AmazonAuthError, AmazonAuthSignInError
|
|
16
13
|
from amazonauth.session import AmazonSession, IODefault
|
|
@@ -120,70 +117,7 @@ class CliAuth:
|
|
|
120
117
|
browser_login.login()
|
|
121
118
|
|
|
122
119
|
|
|
123
|
-
@click.
|
|
124
|
-
@click.option("--username", help="An Amazon username.")
|
|
125
|
-
@click.option("--password", help="An Amazon password.")
|
|
126
|
-
@click.option("--debug", is_flag=True, default=False,
|
|
127
|
-
help="Enable debugging and send output to "
|
|
128
|
-
"command line.")
|
|
129
|
-
@click.option("--config-path",
|
|
130
|
-
help="The config path.")
|
|
131
|
-
@click.option("--max-auth-attempts",
|
|
132
|
-
help="The max auth loop attempts to make (successes and failures), passing this overrides config value.")
|
|
133
|
-
@click.option("--output-dir",
|
|
134
|
-
help="The directory where any output files should be produced, passing this overrides config value.")
|
|
135
|
-
@click.option("--domain",
|
|
136
|
-
help="The Amazon domain to target (e.g. amazon.com, amazon.co.uk, amazon.com.au). "
|
|
137
|
-
"Defaults to amazon.com.")
|
|
138
|
-
@click.pass_context
|
|
139
|
-
def amazon_auth_cli(ctx: Context,
|
|
140
|
-
**kwargs: Any) -> None:
|
|
141
|
-
"""
|
|
142
|
-
amazon-auth signs in to Amazon's consumer website and persists the session, so it can be reused from the
|
|
143
|
-
CLI or Python.
|
|
144
|
-
|
|
145
|
-
Documentation can be found at https://amazon-auth.readthedocs.io.
|
|
146
|
-
"""
|
|
147
|
-
ctx.ensure_object(dict)
|
|
148
|
-
for key, value in kwargs.items():
|
|
149
|
-
if value:
|
|
150
|
-
ctx.obj[key] = value
|
|
151
|
-
|
|
152
|
-
if kwargs["debug"]:
|
|
153
|
-
logger.setLevel(logging.DEBUG)
|
|
154
|
-
logger.addHandler(logging.StreamHandler())
|
|
155
|
-
|
|
156
|
-
data = {}
|
|
157
|
-
if kwargs.get("output_dir"):
|
|
158
|
-
data["output_dir"] = kwargs["output_dir"]
|
|
159
|
-
if kwargs.get("max_auth_attempts"):
|
|
160
|
-
data["max_auth_attempts"] = kwargs["max_auth_attempts"]
|
|
161
|
-
if kwargs.get("domain"):
|
|
162
|
-
data["domain"] = kwargs["domain"]
|
|
163
|
-
ctx.obj["conf_data"] = data
|
|
164
|
-
|
|
165
|
-
if ctx.invoked_subcommand == "version":
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
try:
|
|
169
|
-
ctx.obj["conf"] = AmazonAuthConfig(config_path=kwargs.get("config_path"),
|
|
170
|
-
data=data)
|
|
171
|
-
except AmazonAuthError as e:
|
|
172
|
-
ctx.fail(str(e))
|
|
173
|
-
|
|
174
|
-
username = kwargs.get("username")
|
|
175
|
-
password = kwargs.get("password")
|
|
176
|
-
|
|
177
|
-
amazon_session = AmazonSession(username,
|
|
178
|
-
password,
|
|
179
|
-
debug=kwargs["debug"],
|
|
180
|
-
io=IOClick(),
|
|
181
|
-
config=ctx.obj["conf"])
|
|
182
|
-
|
|
183
|
-
ctx.obj["amazon_session"] = amazon_session
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
@amazon_auth_cli.command(short_help="Check if a persisted session exists.")
|
|
120
|
+
@click.command(short_help="Check if a persisted session exists.")
|
|
187
121
|
@click.pass_context
|
|
188
122
|
@click.option("--verify", is_flag=True, default=False,
|
|
189
123
|
help="Also ask Amazon whether it still accepts the persisted session.")
|
|
@@ -209,7 +143,7 @@ def check_session(ctx: Context, **kwargs: Any) -> None:
|
|
|
209
143
|
ctx.fail(str(e))
|
|
210
144
|
|
|
211
145
|
|
|
212
|
-
@
|
|
146
|
+
@click.command()
|
|
213
147
|
@click.pass_context
|
|
214
148
|
@click.option("--browser", is_flag=True, default=False,
|
|
215
149
|
help="Sign in with a browser window, so your credentials never need to be stored. "
|
|
@@ -236,7 +170,7 @@ def login(ctx: Context, **kwargs: Any) -> None:
|
|
|
236
170
|
click.echo("Info: Successfully logged in to Amazon, session persisted.\n")
|
|
237
171
|
|
|
238
172
|
|
|
239
|
-
@
|
|
173
|
+
@click.command()
|
|
240
174
|
@click.pass_context
|
|
241
175
|
def logout(ctx: Context) -> None:
|
|
242
176
|
"""
|
|
@@ -246,17 +180,3 @@ def logout(ctx: Context) -> None:
|
|
|
246
180
|
amazon_session.logout()
|
|
247
181
|
|
|
248
182
|
click.echo("Info: Successfully logged out of Amazon.\n")
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
@amazon_auth_cli.command()
|
|
252
|
-
@click.pass_context
|
|
253
|
-
def version(ctx: Context) -> None:
|
|
254
|
-
"""
|
|
255
|
-
Show the banner and package version.
|
|
256
|
-
"""
|
|
257
|
-
click.echo(f"amazon-auth/{__version__} Python/{platform.python_version()}")
|
|
258
|
-
ctx.exit(0)
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if __name__ == "__main__":
|
|
262
|
-
amazon_auth_cli(obj={})
|
|
@@ -21,7 +21,7 @@ class AuthConstants:
|
|
|
21
21
|
|
|
22
22
|
config = AmazonAuthConfig(data={"constants_class": "my_module.MyConstants"})
|
|
23
23
|
|
|
24
|
-
URLs and the URL-shaped headers (``Origin``, ``
|
|
24
|
+
URLs and the URL-shaped headers (``Origin``, ``Referer``) are derived from the active
|
|
25
25
|
Amazon domain. ``REQUEST_COOKIES``, ``Accept-Language``, the sign-in
|
|
26
26
|
``openid.assoc_handle``, and ``COOKIES_SET_WHEN_AUTHENTICATED`` are adjusted for known Amazon sites
|
|
27
27
|
(each only when a subclass has not overridden it). The domain is resolved in this precedence order:
|
|
@@ -66,7 +66,6 @@ class AuthConstants:
|
|
|
66
66
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", # noqa: E501
|
|
67
67
|
"Accept-Encoding": "gzip, deflate, br, zstd",
|
|
68
68
|
"Accept-Language": "en-US,en;q=0.9",
|
|
69
|
-
"Host": urlparse(BASE_URL).netloc,
|
|
70
69
|
"Origin": BASE_URL,
|
|
71
70
|
"Referer": f"{SIGN_IN_URL}?{urlencode(SIGN_IN_QUERY_PARAMS)}",
|
|
72
71
|
"Sec-Ch-Ua": '"Chromium";v="149", "Google Chrome";v="149", "Not.A/Brand";v="24"',
|
|
@@ -203,7 +202,6 @@ class AuthConstants:
|
|
|
203
202
|
|
|
204
203
|
headers = dict(vars(self).get("BASE_HEADERS", type(self).BASE_HEADERS))
|
|
205
204
|
headers["Origin"] = base_url
|
|
206
|
-
headers["Host"] = urlparse(base_url).netloc
|
|
207
205
|
headers["Referer"] = f"{sign_in_url}?{urlencode(sign_in_query_params)}"
|
|
208
206
|
if site and site.english_locale and self._requests_default_language():
|
|
209
207
|
headers["Accept-Language"] = self._english_accept_language(site.english_locale, headers["Accept-Language"])
|
|
@@ -208,7 +208,8 @@ class AmazonSession:
|
|
|
208
208
|
:param kwargs: Remaining ``kwargs`` will be passed to :func:`requests.request`.
|
|
209
209
|
:return: The response from the executed request.
|
|
210
210
|
"""
|
|
211
|
-
|
|
211
|
+
headers = {**self.config.constants.BASE_HEADERS, **(kwargs.get("headers") or {})}
|
|
212
|
+
kwargs["headers"] = {name: value for name, value in headers.items() if name.lower() != "host"}
|
|
212
213
|
|
|
213
214
|
if self.debug:
|
|
214
215
|
logger.debug(f"{method} request: {url}")
|
|
@@ -22,7 +22,6 @@ dependencies = [
|
|
|
22
22
|
]
|
|
23
23
|
classifiers = [
|
|
24
24
|
"Development Status :: 4 - Beta",
|
|
25
|
-
"Environment :: Console",
|
|
26
25
|
"Intended Audience :: Developers",
|
|
27
26
|
"Operating System :: OS Independent",
|
|
28
27
|
"Programming Language :: Python :: 3",
|
|
@@ -54,6 +53,10 @@ lxml = [
|
|
|
54
53
|
captcha = [
|
|
55
54
|
"amazoncaptcha>=0.4",
|
|
56
55
|
]
|
|
56
|
+
integration = [
|
|
57
|
+
"pytest-rerunfailures",
|
|
58
|
+
"parameterized"
|
|
59
|
+
]
|
|
57
60
|
docs = [
|
|
58
61
|
"Sphinx",
|
|
59
62
|
"sphinx-notfound-page",
|
|
@@ -79,9 +82,6 @@ dev = [
|
|
|
79
82
|
"responses",
|
|
80
83
|
]
|
|
81
84
|
|
|
82
|
-
[project.scripts]
|
|
83
|
-
amazon-auth = "amazonauth.cli:amazon_auth_cli"
|
|
84
|
-
|
|
85
85
|
[project.urls]
|
|
86
86
|
Changelog = "https://github.com/alexdlaird/amazon-auth/blob/main/CHANGELOG.md"
|
|
87
87
|
Sponsor = "https://github.com/sponsors/alexdlaird"
|
|
@@ -3,14 +3,33 @@ __license__ = "MIT"
|
|
|
3
3
|
|
|
4
4
|
from unittest.mock import patch
|
|
5
5
|
|
|
6
|
+
import click
|
|
6
7
|
import responses
|
|
7
8
|
from click.testing import CliRunner
|
|
8
9
|
|
|
9
|
-
from amazonauth.cli import
|
|
10
|
+
from amazonauth.cli import IOClick, check_session, login, logout
|
|
11
|
+
from amazonauth.conf import AmazonAuthConfig
|
|
10
12
|
from amazonauth.exception import AmazonAuthBrowserNotInstalledError
|
|
13
|
+
from amazonauth.session import AmazonSession
|
|
11
14
|
from tests.unittestcase import UnitTestCase
|
|
12
15
|
|
|
13
16
|
|
|
17
|
+
@click.group()
|
|
18
|
+
@click.option("--username")
|
|
19
|
+
@click.option("--password")
|
|
20
|
+
@click.option("--config-path")
|
|
21
|
+
@click.pass_context
|
|
22
|
+
def downstream_cli(ctx, username, password, config_path):
|
|
23
|
+
ctx.ensure_object(dict)
|
|
24
|
+
ctx.obj["amazon_session"] = AmazonSession(username, password, io=IOClick(),
|
|
25
|
+
config=AmazonAuthConfig(config_path=config_path))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
downstream_cli.add_command(check_session)
|
|
29
|
+
downstream_cli.add_command(login)
|
|
30
|
+
downstream_cli.add_command(logout)
|
|
31
|
+
|
|
32
|
+
|
|
14
33
|
class TestCli(UnitTestCase):
|
|
15
34
|
def setUp(self):
|
|
16
35
|
super().setUp()
|
|
@@ -26,7 +45,7 @@ class TestCli(UnitTestCase):
|
|
|
26
45
|
self.given_login_responses_success()
|
|
27
46
|
|
|
28
47
|
# WHEN
|
|
29
|
-
response = self.runner.invoke(
|
|
48
|
+
response = self.runner.invoke(downstream_cli,
|
|
30
49
|
[
|
|
31
50
|
"--config-path", self.test_config.config_path,
|
|
32
51
|
"--username", "some-username@gmail.com",
|
|
@@ -45,7 +64,7 @@ class TestCli(UnitTestCase):
|
|
|
45
64
|
]
|
|
46
65
|
|
|
47
66
|
def invoke_login_with_browser(self, input=None):
|
|
48
|
-
return self.runner.invoke(
|
|
67
|
+
return self.runner.invoke(downstream_cli,
|
|
49
68
|
["--config-path", self.test_config.config_path, "login", "--browser"],
|
|
50
69
|
input=input)
|
|
51
70
|
|
|
@@ -143,7 +162,7 @@ class TestCli(UnitTestCase):
|
|
|
143
162
|
signout_response = self.given_logout_response_success()
|
|
144
163
|
|
|
145
164
|
# WHEN
|
|
146
|
-
response = self.runner.invoke(
|
|
165
|
+
response = self.runner.invoke(downstream_cli,
|
|
147
166
|
[
|
|
148
167
|
"--config-path", self.test_config.config_path,
|
|
149
168
|
"logout"
|
|
@@ -159,7 +178,7 @@ class TestCli(UnitTestCase):
|
|
|
159
178
|
self.given_persisted_session_exists()
|
|
160
179
|
|
|
161
180
|
# WHEN
|
|
162
|
-
response = self.runner.invoke(
|
|
181
|
+
response = self.runner.invoke(downstream_cli,
|
|
163
182
|
[
|
|
164
183
|
"--config-path", self.test_config.config_path,
|
|
165
184
|
"check-session"
|
|
@@ -173,7 +192,7 @@ class TestCli(UnitTestCase):
|
|
|
173
192
|
@responses.activate
|
|
174
193
|
def test_check_session_command_no_persisted_session(self):
|
|
175
194
|
# WHEN
|
|
176
|
-
response = self.runner.invoke(
|
|
195
|
+
response = self.runner.invoke(downstream_cli,
|
|
177
196
|
[
|
|
178
197
|
"--config-path", self.test_config.config_path,
|
|
179
198
|
"check-session"
|
|
@@ -191,7 +210,7 @@ class TestCli(UnitTestCase):
|
|
|
191
210
|
history_response = self.given_session_check_page_exists()
|
|
192
211
|
|
|
193
212
|
# WHEN
|
|
194
|
-
response = self.runner.invoke(
|
|
213
|
+
response = self.runner.invoke(downstream_cli,
|
|
195
214
|
[
|
|
196
215
|
"--config-path", self.test_config.config_path,
|
|
197
216
|
"check-session",
|
|
@@ -211,7 +230,7 @@ class TestCli(UnitTestCase):
|
|
|
211
230
|
auth_redirect_response = self.given_authenticated_url_redirects_to_login()
|
|
212
231
|
|
|
213
232
|
# WHEN
|
|
214
|
-
response = self.runner.invoke(
|
|
233
|
+
response = self.runner.invoke(downstream_cli,
|
|
215
234
|
[
|
|
216
235
|
"--config-path", self.test_config.config_path,
|
|
217
236
|
"check-session",
|
|
@@ -227,7 +246,7 @@ class TestCli(UnitTestCase):
|
|
|
227
246
|
@responses.activate
|
|
228
247
|
def test_check_session_command_verify_no_persisted_session(self):
|
|
229
248
|
# WHEN
|
|
230
|
-
response = self.runner.invoke(
|
|
249
|
+
response = self.runner.invoke(downstream_cli,
|
|
231
250
|
[
|
|
232
251
|
"--config-path", self.test_config.config_path,
|
|
233
252
|
"check-session",
|
|
@@ -246,7 +265,7 @@ class TestCli(UnitTestCase):
|
|
|
246
265
|
history_response = self.given_session_check_page_exists(status=503)
|
|
247
266
|
|
|
248
267
|
# WHEN
|
|
249
|
-
response = self.runner.invoke(
|
|
268
|
+
response = self.runner.invoke(downstream_cli,
|
|
250
269
|
[
|
|
251
270
|
"--config-path", self.test_config.config_path,
|
|
252
271
|
"check-session",
|
|
@@ -264,7 +283,7 @@ class TestCli(UnitTestCase):
|
|
|
264
283
|
self.given_persisted_session_exists()
|
|
265
284
|
|
|
266
285
|
# WHEN
|
|
267
|
-
response = self.runner.invoke(
|
|
286
|
+
response = self.runner.invoke(downstream_cli,
|
|
268
287
|
[
|
|
269
288
|
"--config-path", self.test_config.config_path,
|
|
270
289
|
"check-session",
|
|
@@ -92,6 +92,17 @@ class TestConstants(UnitTestCase):
|
|
|
92
92
|
self.assertEqual(self._CHROMIUM_UA, config.constants.BASE_HEADERS["User-Agent"])
|
|
93
93
|
self.assertIn("Sec-Ch-Ua", config.constants.BASE_HEADERS)
|
|
94
94
|
|
|
95
|
+
def test_base_headers_have_no_host(self):
|
|
96
|
+
# GIVEN / WHEN
|
|
97
|
+
constants = AuthConstants()
|
|
98
|
+
uk_constants = AmazonAuthConfig(data={"domain": "amazon.co.uk"}).constants
|
|
99
|
+
|
|
100
|
+
# THEN
|
|
101
|
+
self.assertNotIn("Host", AuthConstants.BASE_HEADERS)
|
|
102
|
+
self.assertNotIn("Host", constants.BASE_HEADERS)
|
|
103
|
+
self.assertNotIn("Host", uk_constants.BASE_HEADERS)
|
|
104
|
+
self.assertEqual("https://www.amazon.co.uk", uk_constants.BASE_HEADERS["Origin"])
|
|
105
|
+
|
|
95
106
|
def test_domain_and_chromium_preset_combined(self):
|
|
96
107
|
# GIVEN / WHEN
|
|
97
108
|
config = AmazonAuthConfig(data={
|
|
@@ -253,6 +253,53 @@ class TestSession(UnitTestCase):
|
|
|
253
253
|
# THEN
|
|
254
254
|
self.assertEqual("lc-main=en_US", responses.calls[0].request.headers["Cookie"])
|
|
255
255
|
|
|
256
|
+
@responses.activate
|
|
257
|
+
def test_session_cookie_sent_to_amazon(self):
|
|
258
|
+
# GIVEN
|
|
259
|
+
self.amazon_session.session.cookies.set("session-token", "some-token", domain=".amazon.com", path="/")
|
|
260
|
+
url = f"{self.test_config.constants.BASE_URL}/some/page"
|
|
261
|
+
responses.add(responses.GET, url, body="<html></html>", status=200)
|
|
262
|
+
|
|
263
|
+
# WHEN
|
|
264
|
+
self.amazon_session.get(url)
|
|
265
|
+
|
|
266
|
+
# THEN
|
|
267
|
+
self.assertNotIn("Host", responses.calls[0].request.headers)
|
|
268
|
+
self.assertIn("session-token=some-token", responses.calls[0].request.headers["Cookie"])
|
|
269
|
+
|
|
270
|
+
@responses.activate
|
|
271
|
+
def test_session_cookie_not_sent_on_off_site_redirect(self):
|
|
272
|
+
# GIVEN
|
|
273
|
+
self.amazon_session.session.cookies.set("session-token", "some-token", domain=".amazon.com", path="/")
|
|
274
|
+
url = f"{self.test_config.constants.BASE_URL}/some/page"
|
|
275
|
+
off_site_url = "https://evil.example/x"
|
|
276
|
+
responses.add(responses.GET, url, status=302, headers={"Location": off_site_url})
|
|
277
|
+
responses.add(responses.GET, off_site_url, body="<html></html>", status=200)
|
|
278
|
+
|
|
279
|
+
# WHEN
|
|
280
|
+
self.amazon_session.get(url)
|
|
281
|
+
|
|
282
|
+
# THEN
|
|
283
|
+
self.assertIn("session-token=some-token", responses.calls[0].request.headers["Cookie"])
|
|
284
|
+
self.assertEqual(off_site_url, responses.calls[1].request.url)
|
|
285
|
+
self.assertNotIn("Cookie", responses.calls[1].request.headers)
|
|
286
|
+
|
|
287
|
+
@responses.activate
|
|
288
|
+
def test_caller_host_header_does_not_send_session_cookie_off_site(self):
|
|
289
|
+
# GIVEN
|
|
290
|
+
self.amazon_session.session.cookies.set("session-token", "some-token", domain=".amazon.com", path="/")
|
|
291
|
+
off_site_url = "https://evil.example/x"
|
|
292
|
+
responses.add(responses.GET, off_site_url, body="<html></html>", status=200)
|
|
293
|
+
|
|
294
|
+
for host_header in ("Host", "host", "HOST"):
|
|
295
|
+
with self.subTest(host_header=host_header):
|
|
296
|
+
# WHEN
|
|
297
|
+
self.amazon_session.get(off_site_url, headers={host_header: "www.amazon.com"})
|
|
298
|
+
|
|
299
|
+
# THEN
|
|
300
|
+
self.assertNotIn("Host", responses.calls[-1].request.headers)
|
|
301
|
+
self.assertNotIn("Cookie", responses.calls[-1].request.headers)
|
|
302
|
+
|
|
256
303
|
def test_legacy_cookie_jar_loads_with_site_domain(self):
|
|
257
304
|
# GIVEN
|
|
258
305
|
self.given_persisted_session_exists()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|