Apple登录Python

问题描述

我想使用社交身份验证python创建一个Apple登录。现在,我在下面有一段代码。提出请求时,我收到无效的授予错误。我认为“ id_token”无效。但是我不知道如何获取该id_token,因为在请求之后我得到了id_token。有谁能够帮助我。非常感谢!

headers = {
   'alg': 'ES256','kid': settings.soCIAL_AUTH_APPLE_ID_KEY
}

payload = {
   'iss': settings.soCIAL_AUTH_APPLE_ID_TEAM,'iat': Now,'exp': Now + TOKEN_TTL_SEC,'aud': 'https://appleid.apple.com','sub': settings.soCIAL_AUTH_APPLE_ID_CLIENT,}

client_secret = jwt.encode(
   payload,settings.soCIAL_AUTH_APPLE_ID_SECRET,algorithm='ES256',headers=headers
 ).decode("utf-8")


headers = {'content-type': "application/x-www-form-urlencoded"}
data = {
    'client_id': 'com.scread.app','client_secret': client_secret,'code': 'id_token','grant_type': 'authorization_code'
}

res = requests.post('https://appleid.apple.com/auth/token',data=data,headers=headers)

解决方法

似乎服务ID必须以.app结尾。例如com.company.app。那是我的解决方案。