Skip to content

Returning boolean on token validator #272

Closed

Description

@bisguzar

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.

Activity

  1. added
    feature requestA feature has been asked for or suggested by the community
    on Apr 25, 2021
  2. lbalmaceda commented on May 27, 2021

    @lbalmaceda
    Contributor

    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.

  3. bisguzar commented on May 28, 2021

    @bisguzar
    ContributorAuthor

    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.

  4. stale commented on Aug 28, 2021

    @stale

    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! 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed:staleIssue or PR has not seen activity recentlyfeature requestA feature has been asked for or suggested by the community

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions