如何解决我试图使用python和django 1.9发送对苹果的身份验证请求,但始终给我unsupported_grant_type
我正在尝试使用Python和Django 1.9发送对苹果的身份验证请求,但始终给我unsupported_grant_type
:
def login_with_apple(self,code):
apple_url = "https://appleid.apple.com/auth/token"
client_secret = generate_apple_client_secret()
adapter = AppleOAuth2Adapter(self.request)
headers = {'content-type': 'application/x-www-form-urlencoded'}
data = {'client_id': settings.CLIENT_ID,'client_secret': client_secret,'code': code,'grand_type': 'authorization_code'}
resp = requests.post(url=apple_url,data=data,headers=headers)
access_token = None
if resp.status_code in [200,201]:
try:
access_token = resp.json()
except ValueError:
access_token = dict(parse_qsl(resp.text))
if not access_token or 'acces_token' not in access_token:
raise OAuth2Error(
'Error retrieving access token: %s' % resp.content
)
return access_token
我如何生成client_secret
:
def generate_apple_client_secret():
Now = datetime.utcNow()
claims = {
'iss': settings.soCIAL_AUTH_APPLE_TEAM_ID,'aud': 'https://appleid.apple.com','iat': Now,'exp': Now + timedelta(days=180),'sub': settings.CLIENT_ID,}
headers = {'kid': settings.soCIAL_AUTH_APPLE_KEY_ID,'alg': 'HS256'}
client_secret = jwt.encode(
payload=claims,key=settings.soCIAL_AUTH_APPLE_PRIVATE_KEY,algorithm='HS256',**strong text** headers=headers).decode('utf-8')
return client_secret
user = self.login_with_apple(ser.instance.token)
File "/home/omar/PycharmProjects/Aswaq/oscarapi/views/login.py",line 488,in
login_with_apple
Error retrieving access token: %s' % resp.content
OAuth2Error: Error retrieving access token: {"error":"unsupported_grant_type"}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。