首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DeviceCheck:无法验证授权令牌

DeviceCheck:无法验证授权令牌
EN

Stack Overflow用户
提问于 2018-05-22 08:48:24
回答 1查看 993关注 0票数 7

我正在努力让DeviceCheck工作,在那里,我一直从苹果的服务器:401 Unable to verify authorization token那里得到响应。

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

下面是我的代码示例:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2018-10-03 11:56:03

您需要将有效载荷添加到颁发者键中,然后iat就可以工作了,请检查下面的代码

代码语言:javascript
复制
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....")
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50463463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档