当前位置:   article > 正文

苹果developerAPI 意外401错误NOT_AUTHORIZED_provide a properly configured and signed bearer to

provide a properly configured and signed bearer token, and make sure that it

突然发现苹果api 接口报错,提示如下

  1. {
  2. "errors": [{
  3. "status": "401",
  4. "code": "NOT_AUTHORIZED",
  5. "title": "Authentication credentials are missing or invalid.",
  6. "detail": "Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens"
  7. }]
  8. }

然后去官方网址查看了下,原来是过期时间最多不能超过20分钟

也就是jwt 过期时间最多为20分钟

  1. def __make_jwt_headers(self):
  2. data = {
  3. "iss": self.issuer_id,
  4. "exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=20*60),
  5. "aud": self.JWT_AUD
  6. }
  7. jwt_headers = {
  8. "alg": self.JWT_ALG,
  9. "kid": self.private_key_id,
  10. "typ": "JWT"
  11. }
  12. jwt_encoded = jwt.encode(data, self.p8_private_key, algorithm=self.JWT_ALG, headers=jwt_headers)
  13. headers = {
  14. 'Authorization': 'Bearer %s' % jwt_encoded
  15. }
  16. self.headers = headers
根据 Apple 文档,会话最长持续时间为 20 分钟

https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/419567
推荐阅读
  

闽ICP备14008679号