SatelCreative / spylib

A library to facilitate interfacing with Shopify's API
https://satelcreative.github.io/spylib
MIT License
3 stars 2 forks source link

🐛 add 10 seconds leeway for session token check on the nbf #175

Closed lishanl closed 1 year ago

lishanl commented 1 year ago

encountering the following ImmatureSignatureError from time to time when doing the end to end test with the PIM client.

webapp_1   |   File "/python/app/./middleware/session_token.py", line 47, in __call__
webapp_1   |     session = SessionToken.from_header(headers.get('Authorization'), self.api_key, self.secret)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/spylib/session_token.py", line 81, in from_header
webapp_1   |     payload = decode(
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 119, in decode
webapp_1   |     decoded = self.decode_complete(jwt, key, algorithms, options, **kwargs)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 106, in decode_complete
webapp_1   |     self._validate_claims(payload, merged_options, **kwargs)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 139, in _validate_claims
webapp_1   |     self._validate_nbf(payload, now, leeway)
webapp_1   |   File "/home/python/lib/python3.9/site-packages/jwt/api_jwt.py", line 168, in _validate_nbf
webapp_1   |     raise ImmatureSignatureError("The token is not yet valid (nbf)")
webapp_1   | jwt.exceptions.ImmatureSignatureError: The token is not yet valid (nbf)

did a bit googling and found that's an existing issue others encountered as well ref: Session_token Gives Me Error "The Token Is Not Yet Valid (Nbc)" and the shopify python library has it fixed with the leeway that applies to nbf, exp, iat: Accept 10 seconds clock skew to avoid ImmatureSignatureError

The solution is applied here as well.

lishanl commented 1 year ago

I have update the pyproject.toml to not upate the httpx and fastapi to the latest version because they both contain breaking changes. To be dealt with in another PR: httpx==0.23.1, breaking change on url typing, likely to fastapi==0.87.0, breaking change on testclient

Please refer to the 2 CI failures in the PR.