Skip to content

Commit 3d35fa7

Browse files
v0.0.9 🦢
1 parent 488658f commit 3d35fa7

8 files changed

Lines changed: 28 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.9] - 2021-11-14 :swan:
9+
- Adds `sub`, `access_token`, and `refresh_token` properties to the `Identity`
10+
class
11+
- Adds `py.typed` file
12+
813
## [0.0.8] - 2021-10-31 :shield:
914
- Adds classes to handle `JWT`s validation, but only for `RSA` keys
1015
- Fixes issue (wrong arrangement in test) #5

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.md
2+
include LICENSE
3+
recursive-include guardpost py.typed

guardpost/authentication.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ def __init__(
1010
):
1111
self.claims = claims or {}
1212
self.authentication_mode = authentication_mode
13+
self.access_token: Optional[str] = None
14+
self.refresh_token: Optional[str] = None
1315

14-
def is_authenticated(self):
16+
@property
17+
def sub(self) -> Optional[str]:
18+
return self["sub"]
19+
20+
def is_authenticated(self) -> bool:
1521
return bool(self.authentication_mode)
1622

1723
def __getitem__(self, item):
@@ -26,15 +32,15 @@ def has_claim_value(self, name: str, value: str) -> bool:
2632

2733
class User(Identity):
2834
@property
29-
def id(self):
30-
return self["id"]
35+
def id(self) -> Optional[str]:
36+
return self["id"] or self.sub
3137

3238
@property
33-
def name(self):
39+
def name(self) -> Optional[str]:
3440
return self["name"]
3541

3642
@property
37-
def email(self):
43+
def email(self) -> Optional[str]:
3844
return self["email"]
3945

4046

guardpost/py.typed

Whitespace-only changes.

guardpost/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_logger():
1515
return logging.getLogger("auth-jwts")
1616

1717

18-
def get_running_loop():
18+
def get_running_loop(): # pragma: no cover
1919
if sys.version_info[:2] <= (3, 7):
2020
# For Python 3.6
2121
return asyncio._get_running_loop()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def readme():
88

99
setup(
1010
name="guardpost",
11-
version="0.0.8",
11+
version="0.0.9",
1212
description=(
1313
"Basic framework to handle authentication and authorization "
1414
"in any kind of Python application."

tests/test_authentication.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def test_identity_dictionary_notation():
5555
assert a["foo"] is None
5656

5757

58+
def test_identity_sub():
59+
a = Identity({"sub": "bc5f60df-4c27-49c1-8466-acf32618a6d2"})
60+
61+
assert a.sub == "bc5f60df-4c27-49c1-8466-acf32618a6d2"
62+
63+
5864
def test_user_identity_dictionary_notation():
5965
a = User({"oid": "bc5f60df-4c27-49c1-8466-acf32618a6d2"})
6066

tests/test_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_policy_iadd_syntax():
3939

4040
auth_req = AuthenticatedRequirement()
4141

42+
assert strategy.default_policy is not None
4243
strategy.default_policy += auth_req
4344

4445
assert strategy.default_policy.requirements[0] is auth_req

0 commit comments

Comments
 (0)