【问题标题】:DeviceCheck: Unable to verify authorization tokenDeviceCheck:无法验证授权令牌
【发布时间】:2018-10-31 23:21:09
【问题描述】:

我正在尝试让 DeviceCheck 工作,我不断收到来自 Apple 服务器的此响应:401 Unable to verify authorization token

device_token 正在通过 JSON 有效负载中的 base64 编码字符串发送到我的 python 服务器。有什么想法我可能做错了吗?

这是我的代码示例:

def device_check_query(device_token):  
    data = {  
        'device_token': device_token,  
        'transaction_id': str(uuid4()),  
        'timestamp': int(time.time() * 1000),  
    }  
    jw_token = get_jw_token()  
    headers = {'Authorization': 'Bearer ' + jw_token}  
    response = requests.post(QUERY_URL, json=data, headers=headers)  
    return response.content

def get_jw_token():  
    with open(KEY_FILE, 'r') as cert_file:  
        certificate = cert_file.read()  

    jw_token = jwt.encode(  
        {'iss': TEAM_ID}, certificate,  
        algorithm='ES256',  
        headers={'kid': KEY_ID})  

    return jw_token

【问题讨论】:

标签: python ios authentication jwt devicecheck


【解决方案1】:

您需要在有效负载中添加颁发者密钥和 iat 然后它才能工作,请检查下面的代码

import time
def device_check_query(device_token):  
    data = {  
        'device_token': device_token,  
        'transaction_id': str(uuid.uuid4()),  
        'timestamp': int(time.time() * 1000),  
    }  
    jw_token = get_jw_token()  
    headers = {'Authorization': 'Bearer ' + jw_token}  
    response = requests.post(url, json=data, headers=headers)  
    return response.content

def get_jw_token():  
    with open('myfile.p8', 'r') as cert_file:  
        certificate = cert_file.read()  
    jw_token = jwt.encode(  
        {'iss': issuer,'iat': int(time.time())}, certificate,  
        algorithm='ES256',  
        headers={'kid': keyid})  
    return jw_token
device_check_query(u"1234e323a22133....")

【讨论】:

猜你喜欢
  • 2017-01-11
  • 2018-07-04
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
  • 2021-03-25
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
相关资源
最近更新 更多