- 
        Couldn't load subscription status. 
- Fork 254
Add option to provide current time when decoding JWT #267
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
base: master
Are you sure you want to change the base?
Conversation
| Codecov Report
 
 @@           Coverage Diff           @@
##           master     #267   +/-   ##
=======================================
  Coverage   92.94%   92.94%           
=======================================
  Files          15       15           
  Lines        1418     1418           
=======================================
  Hits         1318     1318           
  Misses        100      100           
 Continue to review full report at Codecov. 
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependency injection to ease testing? 👍
Dependency injection to improve usability? 👍
Code churn for no discernible reason? 👎
If you have a good reason for prepending the now parameter like you did, I'll definitely consider it, but I haven't seen a good reason for it yet. Please point me to it if I missed it. 😅
        
          
                jose/jwt.py
              
                Outdated
          
        
      |  | ||
|  | ||
| def _validate_claims(claims, audience=None, issuer=None, subject=None, algorithm=None, access_token=None, options=None): | ||
| def _validate_claims(now, claims, audience=None, issuer=None, subject=None, algorithm=None, access_token=None, options=None): | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change the function signature? Wouldn't it be easier to append now=None to the end of the parameter list and keep the function signature the same? And then use
now = now or datetime.utcnow()to default to datetime.utcnow(), just in case anybody is using these private methods.
I realize that they're private methods, and people are signing up to keep their code up-to-date when they use these private methods, but there's no point in code churn without a good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was not part of the public API (this particular function does not even have docstring to serve as a documentation), so there was no hesitation to change the signature. Making now (required) positional argument better states the intention to me.
Either way, updated.
7a66496    to
    9667b78      
    Compare
  
    | Hi folks, this feature would be very welcome, any chance this gets accepted? | 
9667b78    to
    8fd0ed9      
    Compare
  
    | Rebased with latest  | 
freezegun:freeze_timeorunittest.mock:patch. Less monkey patching == better code.