|
@@ -52,6 +52,8 @@ class AppToAppView(View):
|
|
|
return self.disable_skill_and_unlink_account(user_id, response)
|
|
|
elif operation == 'getSkillPageURL': # 获取skill页面URL(取消链接)
|
|
|
return self.get_skill_page_url(response)
|
|
|
+ elif operation == 'getAlexaAppUrl': # 获取重定向至Alexa app的url
|
|
|
+ return self.get_alexa_app_url(user_id, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -239,3 +241,47 @@ class AppToAppView(View):
|
|
|
elif request_method == 'delete':
|
|
|
r = requests.delete(headers=headers, url=url, timeout=30)
|
|
|
return r
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_alexa_app_url(user_id, request_dict, response):
|
|
|
+ response_type = request_dict.get('response_type', None)
|
|
|
+ operate = request_dict.get('operate', None)
|
|
|
+ state = request_dict.get('state', None)
|
|
|
+ redirect_uri = request_dict.get('redirect_uri', None)
|
|
|
+
|
|
|
+ if not all([state, redirect_uri]) or response_type not in ['code', 'token'] or operate not in ['accept', 'deny']:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ redirect_uri += '?state={}'.format(state)
|
|
|
+
|
|
|
+ if operate == 'accept':
|
|
|
+ redirect_uri += '&source=app'
|
|
|
+ if response_type == 'code':
|
|
|
+ # 获取用户授权码
|
|
|
+ base_url = 'https://{}'.format(ALEXA_DOMAIN)
|
|
|
+ url = base_url + '/appToApp/oa2/getAuthCode'
|
|
|
+ region_code = 'EU'
|
|
|
+ if CONFIG_INFO != CONFIG_EUR:
|
|
|
+ region_code = 'US'
|
|
|
+ params = {
|
|
|
+ 'user_id': user_id,
|
|
|
+ 'region_code': region_code
|
|
|
+ }
|
|
|
+ r = requests.get(url=url, params=params, timeout=10)
|
|
|
+ assert r.status_code == 200
|
|
|
+ res = eval(r.content)
|
|
|
+ user_authorization_code = res['res']['user_authorization_code']
|
|
|
+ redirect_uri += '&code={}'.format(user_authorization_code)
|
|
|
+ elif response_type == 'token':
|
|
|
+ # 获取令牌
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ redirect_uri += '&error=access_denied&error_description=The%20user%20denied%20the%20request.%20'
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'redirect_uri': redirect_uri
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|