|
@@ -180,10 +180,9 @@ class AppToAppView(View):
|
|
request_method = 'delete'
|
|
request_method = 'delete'
|
|
try:
|
|
try:
|
|
r = cls.refresh_access_token(user_id, request_method)
|
|
r = cls.refresh_access_token(user_id, request_method)
|
|
- if r is None:
|
|
|
|
- return response.json(173)
|
|
|
|
- # 2xx响应状态码为成功
|
|
|
|
- assert str(r.status_code)[:1] == '2'
|
|
|
|
|
|
+ if r is not None:
|
|
|
|
+ # 2xx响应状态码为成功
|
|
|
|
+ assert str(r.status_code)[:1] == '2'
|
|
AlexaOauth.objects.filter(user_id=user_id).update(link_status=0)
|
|
AlexaOauth.objects.filter(user_id=user_id).update(link_status=0)
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -202,10 +201,14 @@ class AppToAppView(View):
|
|
@staticmethod
|
|
@staticmethod
|
|
def refresh_access_token(user_id, request_method):
|
|
def refresh_access_token(user_id, request_method):
|
|
if request_method not in ['get', 'delete']:
|
|
if request_method not in ['get', 'delete']:
|
|
- return None
|
|
|
|
- alexa_oauth_qs = AlexaOauth.objects.filter(user_id=user_id).values('alexa_api_endpoint', 'amazon_refresh_token')
|
|
|
|
|
|
+ return
|
|
|
|
+ alexa_oauth_qs = AlexaOauth.objects.filter(user_id=user_id).\
|
|
|
|
+ values('alexa_api_endpoint', 'amazon_refresh_token', 'link_status')
|
|
if not alexa_oauth_qs:
|
|
if not alexa_oauth_qs:
|
|
- return None
|
|
|
|
|
|
+ return
|
|
|
|
+ # 已连接,但token失效
|
|
|
|
+ if alexa_oauth_qs[0]['link_status'] == 2:
|
|
|
|
+ return
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
# 使用刷新令牌获取新的访问令牌
|
|
# 使用刷新令牌获取新的访问令牌
|
|
# https://developer.amazon.com/zh/docs/login-with-amazon/authorization-code-grant.html#using-refresh-tokens
|
|
# https://developer.amazon.com/zh/docs/login-with-amazon/authorization-code-grant.html#using-refresh-tokens
|