Skip to content

Commit 644d7a4

Browse files
committed
Make all user attributes accessible by __getattr__
1 parent de01d32 commit 644d7a4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

examples/demonstration/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
scope=["user:email"],
2424
claims=Claims(
2525
picture="avatar_url",
26-
identity=lambda user: "%s:%s" % (user.get("provider"), user.get("id")),
26+
identity=lambda user: f"{user.provider}:{user.id}",
2727
),
2828
),
2929
OAuth2Client(
@@ -32,7 +32,7 @@
3232
client_secret=os.getenv("OAUTH2_GOOGLE_CLIENT_SECRET"),
3333
scope=["openid", "profile", "email"],
3434
claims=Claims(
35-
identity=lambda user: "%s:%s" % (user.get("provider"), user.get("sub")),
35+
identity=lambda user: f"{user.provider}:{user.sub}",
3636
),
3737
),
3838
]

src/fastapi_oauth2/middleware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def __getprop__(self, item, default="") -> Any:
115115
return item(self)
116116
return self.get(item, default)
117117

118+
__getattr__ = __getprop__
119+
118120

119121
class OAuth2Backend(AuthenticationBackend):
120122
"""Authentication backend for AuthenticationMiddleware."""

0 commit comments

Comments
 (0)