Hydro-Quebec-API-Wrapper 4.3.0__tar.gz → 4.4.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.
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.pylintrc +2 -2
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0/Hydro_Quebec_API_Wrapper.egg-info}/PKG-INFO +1 -1
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/Hydro_Quebec_API_Wrapper.egg-info/SOURCES.txt +2 -1
- {hydro_quebec_api_wrapper-4.3.0/Hydro_Quebec_API_Wrapper.egg-info → hydro_quebec_api_wrapper-4.4.0}/PKG-INFO +1 -1
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/client.py +78 -33
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/consts.py +66 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/webuser.py +8 -1
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/unit/test_login_flow.py +17 -0
- hydro_quebec_api_wrapper-4.4.0/tests/unit/test_mobile_client.py +180 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.coveragerc +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.devcontainer/Dockerfile +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.devcontainer/devcontainer.json +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.flake8 +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.github/scripts/home_assistant_versions.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.github/workflows/ci.yml +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.github/workflows/release.yml +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.gitignore +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.gitlab-ci.yml +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.pre-commit-config.yaml +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/Hydro_Quebec_API_Wrapper.egg-info/dependency_links.txt +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/Hydro_Quebec_API_Wrapper.egg-info/entry_points.txt +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/Hydro_Quebec_API_Wrapper.egg-info/requires.txt +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/Hydro_Quebec_API_Wrapper.egg-info/top_level.txt +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/LICENSE +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/MANIFEST.in +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/README.md +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/config.default.yaml +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/conflict_test_requirements.txt +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/Makefile +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/make.bat +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/_static/custom.css +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/_static/hydroqc-logo-128.png +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/_static/hydroqc-logo.svg +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/conf.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/external/description-des-codes-interruption.pdf +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/index.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.contract.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.hydro_api.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.peak.cpc.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.peak.dpc.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.peak.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.types.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/modules.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/todo.rst +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/examples/hydro.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/account.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/common.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_d.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_d_cpc.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_dpc.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_dt.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_m.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_m_gdp.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_residential.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/outage.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/customer.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/diagnostic.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/error.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/cache.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/mfa.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/logger.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/basepeak.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/basepeakhandler.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/handler.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/peak.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/consts.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/handler.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/peak.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/public_client.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/py.typed +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/timerange.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/account.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/common.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/consump.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/contract.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/cpc.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/dpc.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/dt.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/types/outage.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/utils.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/logo/hydroqc-logo-128.png +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/logo/hydroqc-logo.svg +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/pyproject.toml +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/renovate.json5 +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/setup.cfg +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/test_requirements.txt +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/conftest.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_common.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_d.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_d_cpc.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_dpc.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_dt.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_m.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_m_gdp.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/test_basic.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/test_timerange.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/tools.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/unit/__init__.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/unit/test_mfa.py +0 -0
- {hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tox.ini +0 -0
|
@@ -201,7 +201,7 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
|
|
201
201
|
single-line-if-stmt=no
|
|
202
202
|
|
|
203
203
|
# Maximum number of lines in a module
|
|
204
|
-
max-module-lines=
|
|
204
|
+
max-module-lines=1700
|
|
205
205
|
|
|
206
206
|
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
|
207
207
|
# tab).
|
|
@@ -245,7 +245,7 @@ max-statements=70
|
|
|
245
245
|
max-parents=7
|
|
246
246
|
|
|
247
247
|
# Maximum number of attributes for a class (see R0902).
|
|
248
|
-
max-attributes=
|
|
248
|
+
max-attributes=30
|
|
249
249
|
|
|
250
250
|
# Minimum number of public methods for a class (see R0903).
|
|
251
251
|
min-public-methods=1
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/client.py
RENAMED
|
@@ -31,12 +31,9 @@ from hydroqc.error import (
|
|
|
31
31
|
from hydroqc.hydro_api.cache import CCached
|
|
32
32
|
from hydroqc.hydro_api.consts import (
|
|
33
33
|
ANNUAL_DATA_URL,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
AUTHORIZE_URL,
|
|
34
|
+
AUTH_CLIENT_WEB,
|
|
35
|
+
AUTH_CLIENTS,
|
|
37
36
|
AZB2C_CLIENT_ID_WEB,
|
|
38
|
-
AZB2C_POLICY,
|
|
39
|
-
AZB2C_SCOPE_WEB,
|
|
40
37
|
AZB2C_TIMEOUT_SKEW_SECS,
|
|
41
38
|
CONSO_CSV_URL,
|
|
42
39
|
CONSO_OVERVIEW_CSV_URL,
|
|
@@ -60,7 +57,6 @@ from hydroqc.hydro_api.consts import (
|
|
|
60
57
|
RELATION_URL,
|
|
61
58
|
REQUESTS_TIMEOUT,
|
|
62
59
|
SESSION_URL,
|
|
63
|
-
TOKEN_URL,
|
|
64
60
|
)
|
|
65
61
|
from hydroqc.hydro_api.mfa import (
|
|
66
62
|
B2CPage,
|
|
@@ -128,6 +124,7 @@ class HydroClient:
|
|
|
128
124
|
cookie_jar: aiohttp.CookieJar | None = None,
|
|
129
125
|
refresh_token: str = "",
|
|
130
126
|
refresh_token_expiry: datetime | None = None,
|
|
127
|
+
auth_client: str = AUTH_CLIENT_WEB,
|
|
131
128
|
):
|
|
132
129
|
"""Initialize the client object.
|
|
133
130
|
|
|
@@ -153,8 +150,17 @@ class HydroClient:
|
|
|
153
150
|
needed. Defaults to "".
|
|
154
151
|
refresh_token_expiry: Expiry of ``refresh_token``. Defaults to None,
|
|
155
152
|
which marks the session as already expired.
|
|
153
|
+
auth_client: B2C client to log in with, ``"web"`` (the Espace
|
|
154
|
+
client) or ``"mobile"`` (the Android app, whose refresh token
|
|
155
|
+
lasts 90 days). Defaults to ``"web"``.
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
ValueError: ``auth_client`` is not a known client.
|
|
156
159
|
|
|
157
160
|
"""
|
|
161
|
+
if auth_client not in AUTH_CLIENTS:
|
|
162
|
+
raise ValueError(f"Unknown auth_client: {auth_client!r}")
|
|
163
|
+
self._auth = AUTH_CLIENTS[auth_client]
|
|
158
164
|
self.username: str = username
|
|
159
165
|
self.password: str = password
|
|
160
166
|
self._timeout: int = timeout
|
|
@@ -167,6 +173,7 @@ class HydroClient:
|
|
|
167
173
|
# Azure AD B2C login state
|
|
168
174
|
self._code_verifier: str = ""
|
|
169
175
|
self._mfa_challenge: MFAChallenge | None = None
|
|
176
|
+
self._send_mfa_code: bool = True
|
|
170
177
|
self._pending_cookies: list[dict[str, Any]] = []
|
|
171
178
|
|
|
172
179
|
# OAuth handling variables
|
|
@@ -413,15 +420,18 @@ class HydroClient:
|
|
|
413
420
|
return False
|
|
414
421
|
return True
|
|
415
422
|
|
|
416
|
-
async def login(self) -> LoginStatus:
|
|
423
|
+
async def login(self, *, send_mfa_code: bool = True) -> LoginStatus:
|
|
417
424
|
"""Log in HydroQuebec website.
|
|
418
425
|
|
|
419
426
|
Hydroquebec is using B2C solution for authentication. The policy may now
|
|
420
427
|
stop after the password round trip and ask for a one-time code sent by
|
|
421
428
|
e-mail: :attr:`LoginStatus.MFA_REQUIRED` is then returned and the code
|
|
422
|
-
has to be submitted with :meth:`submit_mfa_code`.
|
|
429
|
+
has to be submitted with :meth:`submit_mfa_code`. Set ``send_mfa_code``
|
|
430
|
+
to ``False`` to stop at that step without asking the portal to send a
|
|
431
|
+
code: only an interactive caller should let the user request one.
|
|
423
432
|
"""
|
|
424
433
|
self._logger.info("Login using %s", self.username)
|
|
434
|
+
self._send_mfa_code = send_mfa_code
|
|
425
435
|
|
|
426
436
|
# Reset cache
|
|
427
437
|
self.reset()
|
|
@@ -478,10 +488,10 @@ class HydroClient:
|
|
|
478
488
|
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
|
|
479
489
|
}
|
|
480
490
|
params = {
|
|
481
|
-
"redirect_uri":
|
|
482
|
-
"client_id":
|
|
491
|
+
"redirect_uri": self._auth.redirect_uri,
|
|
492
|
+
"client_id": self._auth.client_id,
|
|
483
493
|
"response_type": "code",
|
|
484
|
-
"scope":
|
|
494
|
+
"scope": self._auth.scope,
|
|
485
495
|
"prompt": prompt,
|
|
486
496
|
"ui_locales": "fr",
|
|
487
497
|
"code_challenge": code_challenge,
|
|
@@ -492,7 +502,11 @@ class HydroClient:
|
|
|
492
502
|
# Allow redirects for the initial authorize call
|
|
493
503
|
# (Azure B2C sometimes issues a 302 before the final HTML)
|
|
494
504
|
res = await self.http_request(
|
|
495
|
-
|
|
505
|
+
self._auth.authorize_url,
|
|
506
|
+
"get",
|
|
507
|
+
headers=headers,
|
|
508
|
+
params=params,
|
|
509
|
+
allow_redirects=True,
|
|
496
510
|
)
|
|
497
511
|
if res.status != 200:
|
|
498
512
|
self._logger.error(
|
|
@@ -510,7 +524,7 @@ class HydroClient:
|
|
|
510
524
|
``signInName`` and ``password``, the ``x-csrf-token`` header set to the
|
|
511
525
|
value extracted from the sign-in page and the session cookies.
|
|
512
526
|
"""
|
|
513
|
-
url =
|
|
527
|
+
url = self._auth.auth_url + "?tx=" + transid + "&p=" + self._auth.policy
|
|
514
528
|
headers = {
|
|
515
529
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
516
530
|
"accept": "application/json, text/javascript, */*; q=0.01",
|
|
@@ -552,7 +566,7 @@ class HydroClient:
|
|
|
552
566
|
``SelfAsserted`` when the call follows the verification page.
|
|
553
567
|
"""
|
|
554
568
|
url = (
|
|
555
|
-
|
|
569
|
+
self._auth.auth_url.rsplit("/", 1)[0]
|
|
556
570
|
+ "/api/"
|
|
557
571
|
+ api
|
|
558
572
|
+ "/confirmed?csrf_token="
|
|
@@ -560,7 +574,7 @@ class HydroClient:
|
|
|
560
574
|
+ "&tx="
|
|
561
575
|
+ transid
|
|
562
576
|
+ "&p="
|
|
563
|
-
+
|
|
577
|
+
+ self._auth.policy
|
|
564
578
|
)
|
|
565
579
|
if api == "CombinedSigninAndSignup":
|
|
566
580
|
url += "&rememberMe=false"
|
|
@@ -658,7 +672,8 @@ class HydroClient:
|
|
|
658
672
|
self.username,
|
|
659
673
|
challenge.description,
|
|
660
674
|
)
|
|
661
|
-
|
|
675
|
+
if self._send_mfa_code:
|
|
676
|
+
await self.request_mfa_code()
|
|
662
677
|
return LoginStatus.MFA_REQUIRED
|
|
663
678
|
|
|
664
679
|
async def request_mfa_code(self) -> bool:
|
|
@@ -841,10 +856,10 @@ class HydroClient:
|
|
|
841
856
|
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
|
|
842
857
|
}
|
|
843
858
|
params = {
|
|
844
|
-
"redirect_uri":
|
|
845
|
-
"client_id":
|
|
859
|
+
"redirect_uri": self._auth.redirect_uri,
|
|
860
|
+
"client_id": self._auth.client_id,
|
|
846
861
|
"response_type": "code",
|
|
847
|
-
"scope":
|
|
862
|
+
"scope": self._auth.scope,
|
|
848
863
|
"prompt": "none",
|
|
849
864
|
"ui_locales": "fr",
|
|
850
865
|
"code_challenge": code_challenge,
|
|
@@ -852,7 +867,7 @@ class HydroClient:
|
|
|
852
867
|
"mobile": "false",
|
|
853
868
|
}
|
|
854
869
|
res = await self.http_request(
|
|
855
|
-
|
|
870
|
+
self._auth.authorize_url,
|
|
856
871
|
"get",
|
|
857
872
|
headers=headers,
|
|
858
873
|
params=params,
|
|
@@ -873,13 +888,15 @@ class HydroClient:
|
|
|
873
888
|
headers = {"content-type": "application/x-www-form-urlencoded", "accept": "*/*"}
|
|
874
889
|
data = {
|
|
875
890
|
"grant_type": "authorization_code",
|
|
876
|
-
"client_id":
|
|
877
|
-
"redirect_uri":
|
|
891
|
+
"client_id": self._auth.client_id,
|
|
892
|
+
"redirect_uri": self._auth.redirect_uri,
|
|
878
893
|
"code": code,
|
|
879
894
|
"code_verifier": self._code_verifier,
|
|
880
895
|
}
|
|
881
896
|
|
|
882
|
-
res = await self.http_request(
|
|
897
|
+
res = await self.http_request(
|
|
898
|
+
self._auth.token_url, "post", headers=headers, data=data
|
|
899
|
+
)
|
|
883
900
|
payload = await self._json_or_empty(res)
|
|
884
901
|
if not payload.get("access_token"):
|
|
885
902
|
self._logger.error(
|
|
@@ -929,6 +946,7 @@ class HydroClient:
|
|
|
929
946
|
sign-on cookie is still valid.
|
|
930
947
|
"""
|
|
931
948
|
return {
|
|
949
|
+
"client_id": self._auth.client_id,
|
|
932
950
|
"refresh_token": self.refresh_token,
|
|
933
951
|
"refresh_token_expiry": self.refresh_token_expiry.isoformat(),
|
|
934
952
|
"access_token": self.access_token,
|
|
@@ -941,7 +959,23 @@ class HydroClient:
|
|
|
941
959
|
}
|
|
942
960
|
|
|
943
961
|
def import_session_state(self, state: Mapping[str, Any]) -> None:
|
|
944
|
-
"""Restore a session produced by :meth:`export_session_state`.
|
|
962
|
+
"""Restore a session produced by :meth:`export_session_state`.
|
|
963
|
+
|
|
964
|
+
The tokens are restored only when the state records the current client
|
|
965
|
+
id. A state with no ``client_id`` predates this field and comes from
|
|
966
|
+
the web client. Tokens of another client cannot be refreshed here, so
|
|
967
|
+
they are dropped and the caller gets a plain interactive login. The
|
|
968
|
+
login host cookies are restored either way, as they belong to the host
|
|
969
|
+
and not to one client.
|
|
970
|
+
"""
|
|
971
|
+
if state.get("client_id", AZB2C_CLIENT_ID_WEB) != self._auth.client_id:
|
|
972
|
+
self._logger.info(
|
|
973
|
+
"Ignoring the tokens of a stored session issued for another "
|
|
974
|
+
"B2C client (an interactive login is required)"
|
|
975
|
+
)
|
|
976
|
+
self._restore_session_cookies(state)
|
|
977
|
+
return
|
|
978
|
+
|
|
945
979
|
refresh_token = state.get("refresh_token")
|
|
946
980
|
if isinstance(refresh_token, str):
|
|
947
981
|
self.refresh_token = refresh_token
|
|
@@ -958,6 +992,10 @@ class HydroClient:
|
|
|
958
992
|
if isinstance(access_expiry, str):
|
|
959
993
|
self.access_token_expiry = self._parse_datetime(access_expiry)
|
|
960
994
|
|
|
995
|
+
self._restore_session_cookies(state)
|
|
996
|
+
|
|
997
|
+
def _restore_session_cookies(self, state: Mapping[str, Any]) -> None:
|
|
998
|
+
"""Restore the login host cookies of a stored session."""
|
|
961
999
|
cookies = state.get("cookies")
|
|
962
1000
|
if isinstance(cookies, list):
|
|
963
1001
|
if self._cookie_jar is None:
|
|
@@ -984,15 +1022,15 @@ class HydroClient:
|
|
|
984
1022
|
"""Refresh current session."""
|
|
985
1023
|
self._logger.debug("Refreshing access token")
|
|
986
1024
|
|
|
987
|
-
url =
|
|
1025
|
+
url = self._auth.token_url
|
|
988
1026
|
headers = {
|
|
989
1027
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
990
1028
|
"Accept": "application/json, text/plain, */*",
|
|
991
1029
|
}
|
|
992
1030
|
data = {
|
|
993
1031
|
"grant_type": "refresh_token",
|
|
994
|
-
"scope":
|
|
995
|
-
"client_id":
|
|
1032
|
+
"scope": self._auth.scope,
|
|
1033
|
+
"client_id": self._auth.client_id,
|
|
996
1034
|
"refresh_token": self.refresh_token,
|
|
997
1035
|
}
|
|
998
1036
|
|
|
@@ -1108,7 +1146,9 @@ class HydroClient:
|
|
|
1108
1146
|
"Content-Type": "application/json",
|
|
1109
1147
|
"Authorization": "Bearer " + await self._get_access_token(),
|
|
1110
1148
|
}
|
|
1111
|
-
res = await self.http_request(
|
|
1149
|
+
res = await self.http_request(
|
|
1150
|
+
self._auth.api_url(RELATION_URL), "get", headers=headers
|
|
1151
|
+
)
|
|
1112
1152
|
# TODO http errors
|
|
1113
1153
|
data: list[AccountTyping] = await res.json()
|
|
1114
1154
|
return data
|
|
@@ -1122,7 +1162,7 @@ class HydroClient:
|
|
|
1122
1162
|
headers = await self._get_customer_http_headers(applicant_id, customer_id)
|
|
1123
1163
|
params = {"withCredentials": "true"}
|
|
1124
1164
|
api_call_response = await self.http_request(
|
|
1125
|
-
CUSTOMER_INFO_URL,
|
|
1165
|
+
self._auth.api_url(CUSTOMER_INFO_URL),
|
|
1126
1166
|
"get",
|
|
1127
1167
|
headers=headers,
|
|
1128
1168
|
params=params,
|
|
@@ -1168,7 +1208,9 @@ class HydroClient:
|
|
|
1168
1208
|
) -> AccountContractSummaryTyping:
|
|
1169
1209
|
"""Get all account_contract linked to a customer."""
|
|
1170
1210
|
headers = await self._get_customer_http_headers(applicant_id, customer_id)
|
|
1171
|
-
res = await self.http_request(
|
|
1211
|
+
res = await self.http_request(
|
|
1212
|
+
self._auth.api_url(CONTRACT_SUMMARY_URL), "get", headers=headers
|
|
1213
|
+
)
|
|
1172
1214
|
data: AccountContractSummaryTyping = await res.json()
|
|
1173
1215
|
return data
|
|
1174
1216
|
|
|
@@ -1196,7 +1238,10 @@ class HydroClient:
|
|
|
1196
1238
|
}
|
|
1197
1239
|
post_data_str = json_dumps(post_data)
|
|
1198
1240
|
res = await self.http_request(
|
|
1199
|
-
CONTRACT_LIST_URL,
|
|
1241
|
+
self._auth.api_url(CONTRACT_LIST_URL),
|
|
1242
|
+
"post",
|
|
1243
|
+
headers=headers,
|
|
1244
|
+
data=post_data_str,
|
|
1200
1245
|
)
|
|
1201
1246
|
data: ListContractsTyping = await res.json()
|
|
1202
1247
|
# We ask only one contract, so we should have only one
|
|
@@ -1216,7 +1261,7 @@ class HydroClient:
|
|
|
1216
1261
|
headers = await self._get_customer_http_headers(applicant_id, customer_id)
|
|
1217
1262
|
params = {"noContrat": contract_id}
|
|
1218
1263
|
api_call_response = await self.http_request(
|
|
1219
|
-
GET_CPC_API_URL,
|
|
1264
|
+
self._auth.api_url(GET_CPC_API_URL),
|
|
1220
1265
|
"get",
|
|
1221
1266
|
headers=headers,
|
|
1222
1267
|
params=params,
|
|
@@ -1391,7 +1436,7 @@ class HydroClient:
|
|
|
1391
1436
|
headers = await self._get_customer_http_headers(applicant_id, customer_id)
|
|
1392
1437
|
params = {"noContrat": contract_id}
|
|
1393
1438
|
api_call_response = await self.http_request(
|
|
1394
|
-
FLEXD_DATA_URL, "get", params=params, headers=headers
|
|
1439
|
+
self._auth.api_url(FLEXD_DATA_URL), "get", params=params, headers=headers
|
|
1395
1440
|
)
|
|
1396
1441
|
# We can not use res.json() because the response header are not application/json
|
|
1397
1442
|
data: DPCDataTyping = self._load_json(await api_call_response.text())
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/consts.py
RENAMED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
avoid all the /portail/ URLs
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
|
|
8
10
|
# Always get the time using HydroQuebec Local Time
|
|
9
11
|
REQUESTS_TIMEOUT = 30
|
|
10
12
|
REQUESTS_TTL = 1
|
|
@@ -26,6 +28,11 @@ AZB2C_RESPONSE_TYPE = "code"
|
|
|
26
28
|
AZB2C_SCOPE_WEB = (
|
|
27
29
|
"openid https://connexionhq.onmicrosoft.com/hq-clientele/Espace.Client"
|
|
28
30
|
)
|
|
31
|
+
AZB2C_POLICY_MOBILE = "B2C_1A_PRD_signup_signin_mobile"
|
|
32
|
+
AZB2C_SCOPE_MOBILE = (
|
|
33
|
+
"openid offline_access "
|
|
34
|
+
"https://connexionhq.onmicrosoft.com/hq-clientele-mobile/Espace.Client"
|
|
35
|
+
)
|
|
29
36
|
AZB2C_CODE_CHALLENGE_METHOD = "S256"
|
|
30
37
|
|
|
31
38
|
# Time to remove from the token expiration time to avoid calls to fail
|
|
@@ -39,6 +46,9 @@ AUTHORIZE_URL = (
|
|
|
39
46
|
)
|
|
40
47
|
AUTH_URL = f"{HOST_LOGIN}/{AZB2C_TENANT_ID}/{AZB2C_POLICY}/SelfAsserted"
|
|
41
48
|
AUTH_CALLBACK_URL = f"{HOST_SESSION}/oauth2/callback"
|
|
49
|
+
AUTH_CALLBACK_URL_MOBILE = (
|
|
50
|
+
"msauth://com.hydroquebec.mf_android/2TD6UgHUYzHyQirztabBgWTrJNs%3D"
|
|
51
|
+
)
|
|
42
52
|
TOKEN_URL = f"{HOST_LOGIN}/{AZB2C_TENANT_ID}/{AZB2C_POLICY.lower()}/oauth2/v2.0/token"
|
|
43
53
|
|
|
44
54
|
CHECK_SESSION_URL = f"{HOST_LOGIN}/hqam/oauth2/connect/checkSession"
|
|
@@ -130,3 +140,59 @@ GET_CPC_API_URL = (
|
|
|
130
140
|
)
|
|
131
141
|
# IS PORTAL RUNNING
|
|
132
142
|
IS_HYDRO_PORTAL_UP_URL = f"{HOST_SESSION}/portail/fr/group/clientele/gerer-mon-compte"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@dataclass(frozen=True)
|
|
146
|
+
class AuthClient:
|
|
147
|
+
"""Azure B2C client used to log in, with the private API it can call."""
|
|
148
|
+
|
|
149
|
+
client_id: str
|
|
150
|
+
policy: str
|
|
151
|
+
scope: str
|
|
152
|
+
redirect_uri: str
|
|
153
|
+
# Path segment of the private API: /wsapi/<api_channel>/prive/...
|
|
154
|
+
api_channel: str
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def authorize_url(self) -> str:
|
|
158
|
+
"""Return the authorize endpoint of the policy."""
|
|
159
|
+
return (
|
|
160
|
+
f"{HOST_LOGIN}/{AZB2C_TENANT_ID}/{self.policy.lower()}"
|
|
161
|
+
"/oauth2/v2.0/authorize"
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def auth_url(self) -> str:
|
|
166
|
+
"""Return the SelfAsserted endpoint of the policy."""
|
|
167
|
+
return f"{HOST_LOGIN}/{AZB2C_TENANT_ID}/{self.policy}/SelfAsserted"
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def token_url(self) -> str:
|
|
171
|
+
"""Return the token endpoint of the policy."""
|
|
172
|
+
return f"{HOST_LOGIN}/{AZB2C_TENANT_ID}/{self.policy.lower()}/oauth2/v2.0/token"
|
|
173
|
+
|
|
174
|
+
def api_url(self, url: str) -> str:
|
|
175
|
+
"""Return a private API URL (declared on /wsapi/web/) for this client."""
|
|
176
|
+
return url.replace("/wsapi/web/", f"/wsapi/{self.api_channel}/", 1)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
AUTH_CLIENT_WEB = "web"
|
|
180
|
+
AUTH_CLIENT_MOBILE = "mobile"
|
|
181
|
+
AUTH_CLIENTS = {
|
|
182
|
+
AUTH_CLIENT_WEB: AuthClient(
|
|
183
|
+
client_id=AZB2C_CLIENT_ID_WEB,
|
|
184
|
+
policy=AZB2C_POLICY,
|
|
185
|
+
scope=AZB2C_SCOPE_WEB,
|
|
186
|
+
redirect_uri=AUTH_CALLBACK_URL,
|
|
187
|
+
api_channel="web",
|
|
188
|
+
),
|
|
189
|
+
# Client of the official Android app: offline_access gives it a 90-day
|
|
190
|
+
# sliding refresh token, so the e-mail code is not asked every day.
|
|
191
|
+
AUTH_CLIENT_MOBILE: AuthClient(
|
|
192
|
+
client_id=AZB2C_CLIENT_ID_MOBILE,
|
|
193
|
+
policy=AZB2C_POLICY_MOBILE,
|
|
194
|
+
scope=AZB2C_SCOPE_MOBILE,
|
|
195
|
+
redirect_uri=AUTH_CALLBACK_URL_MOBILE,
|
|
196
|
+
api_channel="mobile",
|
|
197
|
+
),
|
|
198
|
+
}
|
|
@@ -12,6 +12,7 @@ from hydroqc.consts import LoginStatus
|
|
|
12
12
|
from hydroqc.customer import Customer
|
|
13
13
|
from hydroqc.error import HydroQcError
|
|
14
14
|
from hydroqc.hydro_api.client import HydroClient
|
|
15
|
+
from hydroqc.hydro_api.consts import AUTH_CLIENT_WEB
|
|
15
16
|
from hydroqc.logger import get_logger
|
|
16
17
|
|
|
17
18
|
|
|
@@ -35,8 +36,13 @@ class WebUser:
|
|
|
35
36
|
cookie_jar: aiohttp.CookieJar | None = None,
|
|
36
37
|
refresh_token: str = "",
|
|
37
38
|
refresh_token_expiry: datetime | None = None,
|
|
39
|
+
auth_client: str = AUTH_CLIENT_WEB,
|
|
38
40
|
):
|
|
39
|
-
"""Create a new Hydroquebec webuser.
|
|
41
|
+
"""Create a new Hydroquebec webuser.
|
|
42
|
+
|
|
43
|
+
``auth_client`` selects the B2C client, ``"web"`` (default) or
|
|
44
|
+
``"mobile"``, see :class:`HydroClient`.
|
|
45
|
+
"""
|
|
40
46
|
self._hydro_client = HydroClient(
|
|
41
47
|
username,
|
|
42
48
|
password,
|
|
@@ -47,6 +53,7 @@ class WebUser:
|
|
|
47
53
|
cookie_jar=cookie_jar,
|
|
48
54
|
refresh_token=refresh_token,
|
|
49
55
|
refresh_token_expiry=refresh_token_expiry,
|
|
56
|
+
auth_client=auth_client,
|
|
50
57
|
)
|
|
51
58
|
self._username: str = username
|
|
52
59
|
self._log_level: str | None = log_level
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/unit/test_login_flow.py
RENAMED
|
@@ -70,6 +70,23 @@ async def test_login_reports_mfa_for_a_code_step() -> None:
|
|
|
70
70
|
await client.close_session()
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
74
|
+
async def test_login_can_skip_requesting_the_code() -> None:
|
|
75
|
+
"""A background caller can stop at the code step without sending an e-mail."""
|
|
76
|
+
transport = build_mfa_login()
|
|
77
|
+
client = build_client(transport)
|
|
78
|
+
|
|
79
|
+
assert await client.login(send_mfa_code=False) is LoginStatus.MFA_REQUIRED
|
|
80
|
+
assert client._mfa_challenge is not None
|
|
81
|
+
assert not transport.called(SEND_CODE_URL)
|
|
82
|
+
|
|
83
|
+
# The caller that actually asks the user for the code sends it explicitly.
|
|
84
|
+
assert await client.request_mfa_code() is True
|
|
85
|
+
assert transport.called(SEND_CODE_URL)
|
|
86
|
+
|
|
87
|
+
await client.close_session()
|
|
88
|
+
|
|
89
|
+
|
|
73
90
|
@pytest.mark.asyncio(loop_scope="module")
|
|
74
91
|
async def test_login_reports_mfa_from_a_redirect() -> None:
|
|
75
92
|
"""A redirect to the verification page is also recognised."""
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Pin the Azure AD B2C parameters of the web and mobile clients.
|
|
2
|
+
|
|
3
|
+
The web client stays the default. The mobile client is opt-in: its client id,
|
|
4
|
+
redirect URI, policy, scope and ``offline_access`` refresh grant are what make
|
|
5
|
+
the 90-day sliding session possible.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from hydroqc.consts import LoginStatus
|
|
15
|
+
from hydroqc.hydro_api.consts import (
|
|
16
|
+
AUTH_CLIENT_MOBILE,
|
|
17
|
+
AUTH_CLIENT_WEB,
|
|
18
|
+
AUTH_CLIENTS,
|
|
19
|
+
AZB2C_CLIENT_ID_MOBILE,
|
|
20
|
+
AZB2C_CLIENT_ID_WEB,
|
|
21
|
+
RELATION_URL,
|
|
22
|
+
)
|
|
23
|
+
from tests.unit.test_mfa import (
|
|
24
|
+
FakeResponse,
|
|
25
|
+
ScriptedTransport,
|
|
26
|
+
build_client,
|
|
27
|
+
build_plain_login,
|
|
28
|
+
token_body,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
TOKEN_URL = "oauth2/v2.0/token"
|
|
32
|
+
AUTHORIZE_URL = "oauth2/v2.0/authorize"
|
|
33
|
+
BOTH_CLIENTS = pytest.mark.parametrize("name", [AUTH_CLIENT_WEB, AUTH_CLIENT_MOBILE])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _call(
|
|
37
|
+
transport: ScriptedTransport, method: str, url_part: str
|
|
38
|
+
) -> tuple[str, dict[str, Any]]:
|
|
39
|
+
"""Return the URL and kwargs of the last recorded call to ``url_part``."""
|
|
40
|
+
for call_method, url, kwargs in reversed(transport.calls):
|
|
41
|
+
if call_method == method and url_part in url:
|
|
42
|
+
return url, kwargs
|
|
43
|
+
raise AssertionError(f"no {method} call matched {url_part}")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_mobile_client_values() -> None:
|
|
47
|
+
"""The mobile client keeps the app's audience, policy and offline_access."""
|
|
48
|
+
mobile = AUTH_CLIENTS[AUTH_CLIENT_MOBILE]
|
|
49
|
+
assert mobile.client_id == AZB2C_CLIENT_ID_MOBILE
|
|
50
|
+
assert "offline_access" in mobile.scope
|
|
51
|
+
assert "hq-clientele-mobile" in mobile.scope
|
|
52
|
+
assert mobile.policy.lower().endswith("_mobile")
|
|
53
|
+
assert mobile.redirect_uri.startswith("msauth://com.hydroquebec.mf_android/")
|
|
54
|
+
assert mobile.api_url(RELATION_URL).count("/wsapi/mobile/") == 1
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_web_is_the_default_client() -> None:
|
|
58
|
+
"""Without auth_client the web client and its /wsapi/web/ API are used."""
|
|
59
|
+
client = build_client(ScriptedTransport())
|
|
60
|
+
assert client._auth is AUTH_CLIENTS[AUTH_CLIENT_WEB]
|
|
61
|
+
assert client._auth.client_id == AZB2C_CLIENT_ID_WEB
|
|
62
|
+
assert client._auth.api_url(RELATION_URL) == RELATION_URL
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_unknown_client_is_rejected() -> None:
|
|
66
|
+
"""A typo in auth_client fails at construction, not at login."""
|
|
67
|
+
with pytest.raises(ValueError):
|
|
68
|
+
build_client(ScriptedTransport(), auth_client="android")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@BOTH_CLIENTS
|
|
72
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
73
|
+
async def test_login_uses_the_selected_client(name: str) -> None:
|
|
74
|
+
"""Authorize and code grant carry the selected client's parameters."""
|
|
75
|
+
auth = AUTH_CLIENTS[name]
|
|
76
|
+
transport = build_plain_login()
|
|
77
|
+
client = build_client(transport, auth_client=name)
|
|
78
|
+
|
|
79
|
+
assert await client.login() is LoginStatus.SUCCESS
|
|
80
|
+
|
|
81
|
+
url, kwargs = _call(transport, "get", AUTHORIZE_URL)
|
|
82
|
+
assert auth.policy.lower() in url
|
|
83
|
+
params = kwargs["params"]
|
|
84
|
+
assert params["client_id"] == auth.client_id
|
|
85
|
+
assert params["redirect_uri"] == auth.redirect_uri
|
|
86
|
+
assert params["scope"] == auth.scope
|
|
87
|
+
assert params["code_challenge_method"] == "S256"
|
|
88
|
+
|
|
89
|
+
url, kwargs = _call(transport, "post", TOKEN_URL)
|
|
90
|
+
assert auth.policy.lower() in url
|
|
91
|
+
data = kwargs["data"]
|
|
92
|
+
assert data["grant_type"] == "authorization_code"
|
|
93
|
+
assert data["client_id"] == auth.client_id
|
|
94
|
+
assert data["redirect_uri"] == auth.redirect_uri
|
|
95
|
+
|
|
96
|
+
await client.close_session()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@BOTH_CLIENTS
|
|
100
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
101
|
+
async def test_refresh_uses_selected_client(name: str) -> None:
|
|
102
|
+
"""A refresh posts the selected client id and scope."""
|
|
103
|
+
auth = AUTH_CLIENTS[name]
|
|
104
|
+
transport = ScriptedTransport()
|
|
105
|
+
transport.add("post", TOKEN_URL, FakeResponse(text=token_body()))
|
|
106
|
+
client = build_client(transport, auth_client=name)
|
|
107
|
+
client.refresh_token = "refresh-0"
|
|
108
|
+
|
|
109
|
+
assert await client._refresh_token() is True
|
|
110
|
+
|
|
111
|
+
url, kwargs = _call(transport, "post", TOKEN_URL)
|
|
112
|
+
assert auth.policy.lower() in url
|
|
113
|
+
data = kwargs["data"]
|
|
114
|
+
assert data["grant_type"] == "refresh_token"
|
|
115
|
+
assert data["client_id"] == auth.client_id
|
|
116
|
+
assert data["scope"] == auth.scope
|
|
117
|
+
assert client.refresh_token == "refresh-1"
|
|
118
|
+
|
|
119
|
+
await client.close_session()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@BOTH_CLIENTS
|
|
123
|
+
@pytest.mark.asyncio(loop_scope="module")
|
|
124
|
+
async def test_private_api_uses_selected_client(name: str) -> None:
|
|
125
|
+
"""The private API is called on /wsapi/<channel>/ of the selected client."""
|
|
126
|
+
auth = AUTH_CLIENTS[name]
|
|
127
|
+
transport = ScriptedTransport()
|
|
128
|
+
transport.add("get", "/relations", FakeResponse(text="[]"))
|
|
129
|
+
client = build_client(transport, auth_client=name)
|
|
130
|
+
|
|
131
|
+
async def _token(*_: Any, **__: Any) -> str:
|
|
132
|
+
return "access-1"
|
|
133
|
+
|
|
134
|
+
client._get_access_token = _token
|
|
135
|
+
|
|
136
|
+
await client.get_user_info()
|
|
137
|
+
|
|
138
|
+
url, _ = _call(transport, "get", "/relations")
|
|
139
|
+
assert f"/wsapi/{auth.api_channel}/" in url
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@BOTH_CLIENTS
|
|
143
|
+
def test_session_state_round_trip(name: str) -> None:
|
|
144
|
+
"""A session exported by a client is restored by the same client."""
|
|
145
|
+
client = build_client(ScriptedTransport(), auth_client=name)
|
|
146
|
+
client.refresh_token = "token-1"
|
|
147
|
+
state = client.export_session_state()
|
|
148
|
+
assert state["client_id"] == AUTH_CLIENTS[name].client_id
|
|
149
|
+
|
|
150
|
+
restored = build_client(ScriptedTransport(), auth_client=name)
|
|
151
|
+
restored.import_session_state(state)
|
|
152
|
+
assert restored.refresh_token == "token-1"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@pytest.mark.parametrize(
|
|
156
|
+
"state",
|
|
157
|
+
[
|
|
158
|
+
{"client_id": AZB2C_CLIENT_ID_WEB, "refresh_token": "web-token"},
|
|
159
|
+
# A state predating the client id field comes from the web client.
|
|
160
|
+
{"refresh_token": "web-token"},
|
|
161
|
+
],
|
|
162
|
+
)
|
|
163
|
+
def test_mobile_drops_web_tokens(
|
|
164
|
+
state: dict[str, Any],
|
|
165
|
+
) -> None:
|
|
166
|
+
"""Web tokens are dropped, the login host cookies are kept."""
|
|
167
|
+
cookies = [{"name": "x-ms-cpim-sso", "value": "sso", "domain": "example"}]
|
|
168
|
+
client = build_client(ScriptedTransport(), auth_client=AUTH_CLIENT_MOBILE)
|
|
169
|
+
client.import_session_state({**state, "cookies": cookies})
|
|
170
|
+
|
|
171
|
+
assert client.refresh_token != "web-token"
|
|
172
|
+
assert client.is_session_expired() is True
|
|
173
|
+
assert client._pending_cookies == cookies
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_web_keeps_legacy_state() -> None:
|
|
177
|
+
"""The default client still restores a session exported by 4.3.x."""
|
|
178
|
+
client = build_client(ScriptedTransport())
|
|
179
|
+
client.import_session_state({"refresh_token": "legacy-token"})
|
|
180
|
+
assert client.refresh_token == "legacy-token"
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.devcontainer/devcontainer.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/.github/workflows/release.yml
RENAMED
|
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
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/conflict_test_requirements.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/_static/custom.css
RENAMED
|
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
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/hydroqc.rst
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/docs/source/reference/modules.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/common.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_d.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_d_cpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_dpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_dt.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_m.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/contract_m_gdp.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/contract/outage.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/hydro_api/cache.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/basepeakhandler.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/consts.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/cpc/handler.py
RENAMED
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/__init__.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/consts.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/hydroqc/peak/dpc/handler.py
RENAMED
|
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
|
|
File without changes
|
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_d.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_d_cpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_dpc.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_dt.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_m.py
RENAMED
|
File without changes
|
{hydro_quebec_api_wrapper-4.3.0 → hydro_quebec_api_wrapper-4.4.0}/tests/subtest_contract_m_gdp.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|