Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting and testing errors exposed by update #42

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
default_language_version:
python: python3.8

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand Down
2 changes: 1 addition & 1 deletion fastapi_oidc/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def authenticate_user(auth_header: str = Depends(oauth2_scheme)) -> IDToken:
# Disabled at_hash check since we aren't using the access token
options={"verify_at_hash": False},
)
return token_type.parse_obj(token)
return token_type.model_validate(token)

except (ExpiredSignatureError, JWTError, JWTClaimsError) as err:
raise HTTPException(status_code=401, detail=f"Unauthorized: {err}")
Expand Down
4 changes: 2 additions & 2 deletions fastapi_oidc/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_authentication_server_public_keys(OIDC_spec: Dict):
for signing OIDC ID tokens.
"""
keys_uri = OIDC_spec["jwks_uri"]
r = requests.get(keys_uri)
r = requests.get(keys_uri, timeout=15)
keys = r.json()
return keys

Expand All @@ -24,7 +24,7 @@ def get_signing_algos(OIDC_spec: Dict):
@cached(TTLCache(1, cache_ttl))
def discover_auth_server(*_, base_url: str) -> Dict:
discovery_url = f"{base_url}/.well-known/openid-configuration"
r = requests.get(discovery_url)
r = requests.get(discovery_url, timeout=15)
# If the auth server is failing we can't verify tokens.
# Soooo panic I guess?
r.raise_for_status()
Expand Down
7 changes: 3 additions & 4 deletions fastapi_oidc/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

from pydantic import BaseModel
from pydantic import Extra
from pydantic import ConfigDict


class OIDCConfig(BaseModel):
Expand Down Expand Up @@ -29,15 +29,14 @@ class IDToken(BaseModel):

"""

model_config = ConfigDict(extra="allow")

iss: str
sub: str
aud: str
exp: int
iat: int

class Config:
extra = Extra.allow


class OktaIDToken(IDToken):
"""Pydantic Model for the IDToken returned by Okta's OIDC implementation."""
Expand Down
1 change: 1 addition & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import pytest

from fastapi_oidc import auth
Expand Down
1 change: 1 addition & 0 deletions tests/test_import.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import fastapi_oidc


Expand Down
5 changes: 3 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import pydantic
import pytest

Expand All @@ -21,7 +22,7 @@ def test_IDToken_only_requires_fields_in_OIDC_spec():
iss="ClearAirTurbulence",
sub="ValueJudgement",
aud="SoberCounsel",
exp=3.12,
exp=312,
iat=42,
)

Expand All @@ -31,7 +32,7 @@ def test_IDToken_takes_arbitrary_extra_fields():
iss="ClearAirTurbulence",
sub="ValueJudgement",
aud="SoberCounsel",
exp=3.12,
exp=312,
iat=42,
arbitrary_extra_field="Laskuil-Hliz",
)
Loading