DeviceCheck:无法验证授权令牌

时间:2018-05-22 08:48:25

标签: python ios authentication jwt devicecheck

我正在尝试 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

1 个答案:

答案 0 :(得分:0)

您需要在有效负载中添加颁发者密钥,然后它会起作用,请检查下面的代码

Using configs in /etc/mrjob.conf
Using s3://mrjob-07d6e1cbb9127021/tmp/ as our temp dir on S3
emr_api_params is deprecated and does nothing. Please use extra_cluster_params instead
Could not infer endpoint for bucket commoncrawl; assuming defaults
Copying local files to s3://mrjob-07d6e1cbb9127021/tmp/keywords.ec2-user.20181002.164319.430013/files/...
Adding our job to existing cluster j-22GFG1FUGS12L
Creating temp directory /tmp/phonenumers.ec2-user.20181002.164319.430013
Connect to resource manager at: http://localhost:40750/cluster
Waiting for Step 1 of 1 (s-2OZF2A4TZTS06) to complete...
  RUNNING for 0:00:18
  FAILED
Cluster j-22GFG1FUGS12L is WAITING: Cluster ready after last step failed.
Attempting to fetch counters from logs...
Waiting 10 minutes for logs to transfer to S3... (ctrl-c to skip)