-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contrib-jwt): Add parameters to set the JWT
extras
field (#2313)
* feat(contrib-jwt): Add parameters to set the JWT `extras` field - Add `token_extras` to both `login()` and `create_token()` methods. - Update tests and docs example to use the new parameter. * fix(contrib-jwt): Use `typing.Dict` for 3.8 compatibility
- Loading branch information
1 parent
f73da61
commit 30f748e
Showing
4 changed files
with
30 additions
and
3 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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import sys | ||
from dataclasses import asdict | ||
from datetime import datetime, timedelta, timezone | ||
from typing import Optional | ||
from typing import Any, Dict, Optional | ||
from uuid import uuid4 | ||
|
||
import pytest | ||
|
@@ -20,11 +20,13 @@ | |
@pytest.mark.parametrize( | ||
"token_unique_jwt_id", [None, "10f5c6967783ddd6bb0c4e8262d7097caeae64705e45f83275e3c32eee5d30f2"] | ||
) | ||
@pytest.mark.parametrize("token_extras", [None, {"email": "[email protected]"}]) | ||
def test_token( | ||
algorithm: str, | ||
token_issuer: Optional[str], | ||
token_audience: Optional[str], | ||
token_unique_jwt_id: Optional[str], | ||
token_extras: Optional[Dict[str, Any]], | ||
) -> None: | ||
token_secret = secrets.token_hex() | ||
token = Token( | ||
|
@@ -33,6 +35,7 @@ def test_token( | |
aud=token_audience, | ||
iss=token_issuer, | ||
jti=token_unique_jwt_id, | ||
extras=token_extras or {}, | ||
) | ||
encoded_token = token.encode(secret=token_secret, algorithm=algorithm) | ||
decoded_token = token.decode(encoded_token=encoded_token, secret=token_secret, algorithm=algorithm) | ||
|