fix: userinfo: avoid indexing by None user_id in stateless mode#46
Merged
c00kiemon5ter merged 1 commit intoIdentityPython:masterfrom Nov 15, 2022
Merged
Conversation
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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In stateless mode,
user_idpassed toget_claims_foris alwaysNone.When no claims are available and userinfo is thus also
None,user_idis used as index to self._db, but that triggers aKeyError: None.As
create_access_tokenpopulatesuser_infofield inauthz_infoonly ofuser_infois pythonicallyTrue,user_infopassed here ends up beingNone, not empty dict{}.As the
Userinfoclass does not have access toProvider.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.