Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Returning boolean on token validator #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bisguzar opened this issue Apr 25, 2021 · 3 comments · Fixed by #273
Closed

Returning boolean on token validator #272

bisguzar opened this issue Apr 25, 2021 · 3 comments · Fixed by #273
Labels
closed:stale Issue or PR has not seen activity recently feature request A feature has been asked for or suggested by the community

Comments

@bisguzar
Copy link
Contributor

Hi,

I'm using the token validator of the authentication submodule. It's raising a TokenValidationError if validation failed and returning nothing (so the method returning None by python internals) if validation success.

I'm not sure is it a good idea. If I use this method inside an if condition and assume the token is valid the condition won't work. Because it will return None which is equal to False.

In my opinion, the method should return True when a token is validated. And IMHO it should return False instead of raising an error, but it will be a breaking change. So I'm not sure is it necessary.

@bisguzar bisguzar added the feature request A feature has been asked for or suggested by the community label Apr 25, 2021
@lbalmaceda
Copy link
Contributor

lbalmaceda commented May 27, 2021

Returning a boolean value would make it impossible to know what went wrong with the token verification (e.g. what check triggered the failure). The exception that is raised at least has a message describing the issue. I believe this should help while developing or debugging an app. It's probably not helpful during production, as token validation issues are typically related to a wrong configuration/setup.

i.e. something like this

try:
  sv = AsymmetricSignatureVerifier(jwks_url)
  tv = TokenVerifier(signature_verifier=sv, issuer=issuer, audience=client_id)
  tv.verify(id_token)
except TokenValidationError as err:
  print err

I think making it return the token's payload claims (if all checks passed) is more useful than returning nothing. Since that way, if you want to consume the token contents, you don't need to decode it again.

@bisguzar
Copy link
Contributor Author

Yes, I agree. My point was it is returning None even if all checks passed. I just updated my PR. And it's open for commits by contributors.

@stale
Copy link

stale bot commented Aug 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Aug 28, 2021
@stale stale bot closed this as completed Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:stale Issue or PR has not seen activity recently feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants