def auth_access_token(self, token): """ 验证client id 与client token :return: """ se_token = rest_session.get("access_token") if se_token: if se_token["token"] != token or se_token["expiration"] <= time.time(): # 验证失败或者已过期 response = current_app.make_response( gettext("Invalid AccessToken or AccessToken has expired")) raise AccessTokenError( response.get_data( as_text=True), response=response) else: # 找不到相关token response = current_app.make_response( gettext("Can not find the ClientId matching 'AccessToken'")) raise AccessTokenError( response.get_data( as_text=True), response=response)
def get_current_lang(self): ''' 获取当前语言 :return: ''' lans = list(get_config('babel', 'LANGUAGES').keys()) if request.headers.get('OSR-RestToken'): # RestToken验证请求如果未设置session保存语言, 则使用请求头AcceptLanguges中设置的 return rest_session.get("language", request.accept_languages.best_match(lans)) else: # 普通浏览器客户端, 获取当session中保存的设置 return session.get("language", request.accept_languages.best_match(lans))