Skip to content

Commit e2f7d88

Browse files
fix: userinfo: avoid indexing by None user_id in stateless mode (#46)
In stateless mode, `user_id` passed to `get_claims_for` is always `None`. When no claims are available and userinfo is thus also `None`, `user_id` is used as index to self._db, but that triggers a `KeyError: None`. As `create_access_token` populates `user_info` field in `authz_info` only of `user_info` is pythonically `True`, `user_info` passed here ends up being `None`, not empty dict `{}`. As the `Userinfo` class does not have access to `Provider.stateless`, the easiest fix is to make the db lookup conditional on user_id being pythonically True - which corresponds with not being in stateltess mode.
1 parent 28964c5 commit e2f7d88

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/pyop/userinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ def get_claims_for(self, user_id, requested_claims, userinfo=None):
3131
"""
3232

3333
if not userinfo:
34-
userinfo = self._db[user_id]
34+
userinfo = self._db[user_id] if user_id else {}
3535
claims = {claim: userinfo[claim] for claim in requested_claims if claim in userinfo}
3636
return claims

0 commit comments

Comments
 (0)