Skip to content

Commit

Permalink
Validate the aud claim of JwtAccessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
timhallmann committed Mar 4, 2025
1 parent a9e32ff commit c6700b9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/simple_openid_connect/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,13 @@ class JwtAccessToken(OpenidBaseModel):
scope: Optional[str] = None
"OPTIONAL. Scopes to which the token grants access. Multiple scopes are encoded space separated. If the openid scope value is not present, the behavior is entirely unspecified. Other scope values MAY be present."

def validate_extern(self, issuer: str) -> None:
def validate_extern(self, issuer: str, client_id: Union[str, None] = None) -> None:
"""
Validate this access token with external data for consistency.
:param issuer: The issuer that this token is supposed to originate from.
Should usually be :data:`ProviderMetadata.issuer`.
:param client_id: The client id of this client
"""
# validate issuer
validate_that(
Expand All @@ -358,6 +359,23 @@ def validate_extern(self, issuer: str) -> None:
# validate expiry
validate_that(self.exp > time.time(), "The access token is expired")

# validate audience
if client_id:
validate_that(
self.aud is not None,
"The access token does not contain the required audience value",
)
if isinstance(self.aud, str):
validate_that(
self.aud == client_id,
"The access tokens audience does not contain own client_id",
)
elif isinstance(self.aud, list):
validate_that(
client_id in self.aud,
"The access tokens audience does not contain own client_id",
)


class UserinfoRequest(OpenidBaseModel):
"""
Expand Down

0 comments on commit c6700b9

Please sign in to comment.