-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: client assertion payload check (#300)
* feat: client assertion payload check * feat: client assertion payload check - gitignore and new version * feat: client assertion payload check - fix timings
- Loading branch information
Giuseppe De Marco
authored
Jan 2, 2024
1 parent
d18d99f
commit 4c84fd3
Showing
6 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.2.2" | ||
__version__ = "1.3.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from spid_cie_oidc.entity.utils import iat_now | ||
|
||
from pydantic import BaseModel, AnyHttpUrl, constr, validator | ||
from typing import Literal, Optional, List | ||
|
||
|
||
class ClientAssertion(BaseModel): | ||
iss: AnyHttpUrl | ||
sub: AnyHttpUrl | ||
iat: int | ||
exp: int | ||
jti: Optional[str] | ||
aud: str | List[AnyHttpUrl] | ||
|
||
@validator("sub") | ||
def iss_and_sub_must_match(cls, sub, values): | ||
if values['iss'] != sub: | ||
raise ValueError( | ||
'Client Assertion: iss and sub must have the same value' | ||
) | ||
return sub | ||
|
||
@validator("exp") | ||
def not_expired(cls, exp, values): | ||
_now = iat_now() | ||
if not (values['iat'] <= _now < exp): | ||
raise ValueError( | ||
'Client Assertion: exp must be greater than ' | ||
'iat and less than the current time.' | ||
f'{values["iat"]} <= {_now} < {exp}' | ||
) | ||
return exp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters