@@ -17,8 +17,8 @@ def test_auth(authenticated_user: AuthenticatedUser = Depends(authenticate_user)
17
17
"""
18
18
19
19
from typing import Callable
20
+ from typing import Dict
20
21
from typing import Optional
21
- from typing import Type
22
22
23
23
from fastapi import Depends
24
24
from fastapi import HTTPException
@@ -29,19 +29,15 @@ def test_auth(authenticated_user: AuthenticatedUser = Depends(authenticate_user)
29
29
from jose .exceptions import JWTClaimsError
30
30
31
31
from fastapi_oidc import discovery
32
- from fastapi_oidc .exceptions import TokenSpecificationError
33
- from fastapi_oidc .types import IDToken
34
32
35
33
36
34
def get_auth (
37
- * _ ,
38
35
client_id : str ,
39
- audience : Optional [str ] = None ,
40
36
base_authorization_server_uri : str ,
41
37
issuer : str ,
42
- signature_cache_ttl : int ,
43
- token_type : Type [ IDToken ] = IDToken ,
44
- ) -> Callable [[str ], IDToken ]:
38
+ audience : Optional [ str ] = None ,
39
+ signature_cache_ttl : int = 3600 ,
40
+ ) -> Callable [[str ], Dict ]:
45
41
"""Take configurations and return the authenticate_user function.
46
42
47
43
This function should only be invoked once at the beggining of your
@@ -63,26 +59,19 @@ def get_auth(
63
59
64
60
65
61
Returns:
66
- func: authenticate_user(auth_header: str) -> IDToken (or token_type)
62
+ func: authenticate_user(auth_header: str) -> Dict
67
63
68
64
Raises:
69
65
Nothing intentional
70
66
"""
71
67
72
- if not issubclass (token_type , IDToken ):
73
- raise TokenSpecificationError (
74
- "Invalid argument for token_type. "
75
- "Token type must be a subclass of fastapi_oidc.type.IDToken. "
76
- f"Received { token_type = } "
77
- )
78
-
79
68
oauth2_scheme = OpenIdConnect (
80
69
openIdConnectUrl = f"{ base_authorization_server_uri } /.well-known/openid-configuration"
81
70
)
82
71
83
72
discover = discovery .configure (cache_ttl = signature_cache_ttl )
84
73
85
- def authenticate_user (auth_header : str = Depends (oauth2_scheme )) -> IDToken :
74
+ def authenticate_user (auth_header : str = Depends (oauth2_scheme )) -> Dict :
86
75
"""Validate and parse OIDC ID token against issuer in config.
87
76
Note this function caches the signatures and algorithms of the issuing server
88
77
for signature_cache_ttl seconds.
@@ -92,7 +81,7 @@ def authenticate_user(auth_header: str = Depends(oauth2_scheme)) -> IDToken:
92
81
scenes by Depends.
93
82
94
83
Return:
95
- IDToken (types. IDToken):
84
+ Dict: Dictionary with IDToken information
96
85
97
86
raises:
98
87
HTTPException(status_code=401, detail=f"Unauthorized: {err}")
@@ -103,7 +92,7 @@ def authenticate_user(auth_header: str = Depends(oauth2_scheme)) -> IDToken:
103
92
algorithms = discover .signing_algos (OIDC_discoveries )
104
93
105
94
try :
106
- token = jwt .decode (
95
+ return jwt .decode (
107
96
id_token ,
108
97
key ,
109
98
algorithms ,
@@ -112,7 +101,6 @@ def authenticate_user(auth_header: str = Depends(oauth2_scheme)) -> IDToken:
112
101
# Disabled at_hash check since we aren't using the access token
113
102
options = {"verify_at_hash" : False },
114
103
)
115
- return token_type .parse_obj (token )
116
104
117
105
except (ExpiredSignatureError , JWTError , JWTClaimsError ) as err :
118
106
raise HTTPException (status_code = 401 , detail = f"Unauthorized: { err } " )
0 commit comments