【问题标题】:Create Json web token for DeviceCheck为 DeviceCheck 创建 Json Web 令牌
【发布时间】:2019-02-26 11:30:29
【问题描述】:

目前,我已编写此代码来创建用于 DeviceCheck API 的服务器通信的 JWT。我从苹果返回“无法验证授权令牌”的状态。关于如何修复的任何想法?

import jwt
import uuid
import time
import json


def generateToken(certificate, keyID, teamID):
    ALGORITHM = 'ES256'
    token = jwt.encode(
    {
        'iss': teamID,
        'iat': time.time()
    },
    certificate,
    algorithm= ALGORITHM,
    headers={
        'alg': ALGORITHM,
        'kid': keyID,
        }
    )
    return token

def generateDeviceCheckApplePayload(device_token):
    millis = int(round(time.time() * 1000))
    payload = {
    "device_token" : device_token,
    "transaction_id" : str(uuid.uuid4()),
    "timestamp" : millis,
    }
    payload = json.dumps(payload).encode('utf-8')
    return payload

def verifyDeviceWithApple(device_token):
    auth_token = generateToken(settings.CERTIFICATE, 
        settings.KEY_ID, settings.TEAM_ID)
    headers = {
        'Authorization': 'Bearer ' + str(auth_token),
    }
    data = generateDeviceCheckApplePayload(device_token)
    response = requests.post('https://' + settings.HOST + '/v1/validate_device_token', headers=headers, data=data)
    print(response.text)
    return True

【问题讨论】:

  • 如果您找到解决方案,请提交答案吗?

标签: python ios apple-push-notifications jwt


【解决方案1】:

答案是您需要确保您的 Apple ID 已付款

【讨论】:

    猜你喜欢
    • 2013-11-28
    • 2021-11-02
    • 2018-04-13
    • 2018-10-31
    • 2016-08-01
    • 2023-03-24
    • 2017-09-15
    • 2016-03-23
    • 2018-06-11
    相关资源
    最近更新 更多