DeviceCheck: невозможно проверить токен авторизации - PullRequest
0 голосов
/ 22 мая 2018

Я пытаюсь заставить DeviceCheck работать, где я получаю ответ от сервера Apple: 401 Unable to verify authorization token.

device_token отправляется на мой сервер pythonчерез строку в кодировке base64 в полезной нагрузке JSON.Есть идеи, что я могу делать не так?

Вот мой пример кода:

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 голосов
/ 03 октября 2018

вам нужно добавить в полезную нагрузку ключ эмитента и 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....")
...