diff --git a/src/oauth.py b/src/oauth.py index ae9963247..e89462994 100644 --- a/src/oauth.py +++ b/src/oauth.py @@ -39,10 +39,14 @@ headers={"Referer": host + "/login/"}, ) alphabet = string.ascii_uppercase + string.digits -code_verifier = "".join(secrets.choice(alphabet) for i in range(43 + secrets.randbelow(86))) +code_verifier = "".join( + secrets.choice(alphabet) for i in range(43 + secrets.randbelow(86)) +) code_verifier_base64 = base64.urlsafe_b64encode(code_verifier.encode("utf-8")) code_challenge = hashlib.sha256(code_verifier_base64).digest() -code_challenge_base64 = base64.urlsafe_b64encode(code_challenge).decode("utf-8").replace("=", "") +code_challenge_base64 = ( + base64.urlsafe_b64encode(code_challenge).decode("utf-8").replace("=", "") +) state = "".join(secrets.choice(alphabet) for i in range(15)) data = { @@ -58,14 +62,19 @@ "scope": "openid profile", "allow": "Authorize", } -auth = s.post(host + "/o/authorize/", allow_redirects=False, data=data, headers={"Referer": host + "/o/authorize/"}) -if auth.status_code != 302: # noqa: PLR2004 - print(f"/o/authorize/ returned status code {auth.status_code} - no token today") # noqa: T201 +auth = s.post( + host + "/o/authorize/", + allow_redirects=False, + data=data, + headers={"Referer": host + "/o/authorize/"}, +) +if auth.status_code != 302: + print(f"/o/authorize/ returned status code {auth.status_code} - no token today") sys.exit(1) url = auth.headers["Location"] result = urlparse(url) qs = parse_qs(result.query) -assert state == qs["state"][0] # noqa: S101 +assert state == qs["state"][0] authcode = qs["code"][0] token = s.post( host + "/o/token/", @@ -77,4 +86,4 @@ "code_verifier": code_verifier_base64, }, ) -print(token.json()) # noqa: T201 +print(token.json()) diff --git a/src/requirements/dev.txt b/src/requirements/dev.txt index 655d3bc9a..1efa04325 100644 --- a/src/requirements/dev.txt +++ b/src/requirements/dev.txt @@ -4,7 +4,7 @@ django-debug-toolbar==5.1.0 factory_boy==3.3.3 coverage==7.8.0 pre-commit==4.2.0 -hypothesis==6.130.6 +hypothesis==6.131.3 tblib==3.1.0 unittest-xml-reporting==3.2.0 pipdeptree==2.26.0