Skip to content

Commit 2f45b99

Browse files
authored
Merge pull request #1 from reflex-dev/masenf/pre-commits
fix pre-commit isues
2 parents 3cd7060 + 4bfc0ae commit 2f45b99

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

demos/azure/azure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def index():
2020
rx.button("Logout", on_click=AzureAuthState.redirect_to_logout),
2121
),
2222
rx.button(
23-
"Log In with Microsoft", on_click=AzureAuthState.redirect_to_login
23+
"Log In with Microsoft",
24+
on_click=AzureAuthState.redirect_to_login,
2425
),
2526
),
2627
rx.spinner(),

demos/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
reflex-azure-auth>=0.1
1+
reflex-azure-auth>=0

demos/rxconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
app_name="azure",
55
plugins=[
66
rx.plugins.SitemapPlugin(),
7-
]
7+
],
88
)

reflex_azure_auth/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from reflex_enterprise import App
2424

2525
# Simple cached OIDC metadata + JWKS loader
26-
_OIDC_CACHE: dict[str, object] = {}
26+
_OIDC_CACHE: dict[str, dict] = {}
2727

2828

2929
async def _fetch_oidc_metadata(issuer: str) -> dict:
@@ -36,7 +36,6 @@ async def _fetch_oidc_metadata(issuer: str) -> dict:
3636
resp.raise_for_status()
3737
md = resp.json()
3838
_OIDC_CACHE[key] = md
39-
print(md)
4039
return md
4140

4241

@@ -114,7 +113,7 @@ def _get_jwt_header_payload(token: str) -> tuple[dict, dict]:
114113
_b64_json_decode(parts[0]),
115114
_b64_json_decode(parts[1]),
116115
)
117-
return {}
116+
return {}, {}
118117

119118

120119
def _compute_at_hash(access_token: str, alg: str | None) -> str:
@@ -312,10 +311,9 @@ async def _validate_tokens(self, expiration_only: bool = False) -> bool:
312311
at_hash_claim
313312
and hasattr(self, "_expected_at_hash")
314313
and self._expected_at_hash
315-
):
316-
if at_hash_claim != self._expected_at_hash:
317-
print("at_hash mismatch") # noqa: T201
318-
return False
314+
) and at_hash_claim != self._expected_at_hash:
315+
print("at_hash mismatch") # noqa: T201
316+
return False
319317
except Exception:
320318
return False
321319

tests/test_oidc.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import datetime
32

43
import pytest
@@ -16,7 +15,6 @@ def json(self):
1615

1716
@pytest.mark.asyncio
1817
async def test_fetch_oidc_and_jwks(monkeypatch):
19-
issuer = "https://login.microsoftonline.com/common"
2018
md = {"jwks_uri": "https://example.com/jwks"}
2119
jwks = {"keys": []}
2220

@@ -29,22 +27,15 @@ async def fake_get(url, timeout=10):
2927

3028
class FakeClient:
3129
async def __aenter__(self):
32-
import asyncio
33-
import datetime
34-
3530
import pytest
3631

37-
import reflex_azure_auth as raa
38-
39-
4032
class DummyResp:
4133
def __init__(self, data):
4234
self._data = data
4335

4436
def json(self):
4537
return self._data
4638

47-
4839
@pytest.mark.asyncio
4940
async def test_fetch_oidc_and_jwks(monkeypatch):
5041
issuer = "https://login.microsoftonline.com/common"
@@ -76,7 +67,6 @@ async def get(self, url, timeout=10):
7667
got_jwks = await raa._fetch_jwks(md["jwks_uri"])
7768
assert got_jwks == jwks
7869

79-
8070
@pytest.mark.asyncio
8171
async def test_verify_jwt_claim_checks(monkeypatch):
8272
# Monkeypatch network and jwt.decode to return controlled claims
@@ -92,11 +82,26 @@ async def fake_fetch_jwks(j):
9282

9383
def fake_decode(token, key_set=None):
9484
# return a token that is valid and not expired
95-
return {"iss": issuer, "aud": "api://default", "exp": int((datetime.datetime.utcnow() + datetime.timedelta(minutes=5)).timestamp())}
96-
97-
monkeypatch.setattr(raa, "_fetch_oidc_metadata", fake_fetch_oidc_metadata)
85+
return {
86+
"iss": issuer,
87+
"aud": "api://default",
88+
"exp": int(
89+
(
90+
datetime.datetime.utcnow()
91+
+ datetime.timedelta(minutes=5)
92+
).timestamp()
93+
),
94+
}
95+
96+
monkeypatch.setattr(
97+
raa, "_fetch_oidc_metadata", fake_fetch_oidc_metadata
98+
)
9899
monkeypatch.setattr(raa, "_fetch_jwks", fake_fetch_jwks)
99-
monkeypatch.setattr(raa.jwt, "decode", lambda token, ks: fake_decode(token, ks))
100+
monkeypatch.setattr(
101+
raa.jwt, "decode", lambda token, ks: fake_decode(token, ks)
102+
)
100103

101-
claims = await raa.verify_jwt("dummy", audience="api://default", issuer=issuer)
104+
claims = await raa.verify_jwt(
105+
"dummy", audience="api://default", issuer=issuer
106+
)
102107
assert claims["aud"] == "api://default"

0 commit comments

Comments
 (0)