云端点HTTP Cookie [英] Cloud Endpoints HTTP Cookies
问题描述
我正在使用使用自定义验证的Python应用程序实现Cloud Endpoints( GAE会话)而不是Google帐户。我需要验证来自Javascript客户端的请求,所以我想访问cookie信息。
阅读让我相信这是可能的,但也许没有记录在案。我对App Engine的Java方面并不熟悉,所以我不太清楚如何将该代码片段转换为Python。以下是我的一个方法的示例: 其中 首先,我会鼓励您尝试从客户端使用OAuth 2.0在Tic Tac Toe 示例中。 Cookie发送到Cookie头中的服务器,并且这些值通常在WSGI环境中使用键 $ b,则为os.environ.iteritems() 对于cookie, 更新:已为Python应用程序启用截至版本1.8.0 。要发送cookie,请指定以下内容: 这是一个(不一定全面的列表)的头文件: I am implementing Cloud Endpoints with a Python app that uses custom authentication (GAE Sessions) instead of Google Accounts. I need to authenticate the requests coming from the Javascript client, so I would like to have access to the cookie information. Reading this other question leads me to believe that it is possible, but perhaps not documented. I'm not familiar with the Java side of App Engine, so I'm not quite sure how to translate that snippet into Python. Here is an example of one of my methods: where First, I would encourage you to try to use OAuth 2.0 from your client as is done in the Tic Tac Toe sample. Cookies are sent to the server in the Cookie Header and these values are typically set in the WSGI environment with the keys For cookies, UPDATE: This has been enabled for Python applications as of version 1.8.0. To send cookies through, specify the following: This is a (not necessarily comprehensive list) of headers that make it through: 这篇关于云端点HTTP Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
pre $ EndpointsAPI(remote.Service):
@ endpoints.method (Query_In,Donations_Out,path ='get / donations',
http_method ='GET',name ='get.donations')
def get_donations(self,req):
#Authenticate请求通过cookie
Query_In
和 Donations_Out
都是ProtoRPC消息( messages.Message
)。函数中的参数 req
只是一个 Query_In
的实例,我没有找到任何与HTTP数据相关的属性,但我可能是错的。
'HTTP _...'
设置,其中 ...
对应于标题名称:
http = {key:value如果key.lower()。startswith('http')}
$ b os.getenv('HTTP_COOKIE')
会为您提供您寻求的标题值。不幸的是,默认情况下,这不会通过Google的API基础设施传递。
from google.appengine.ext.endpoints import api_config
AUTH_CONFIG = api_config.ApiAuth(allow_cookie_auth = True)
$ b @ endpoints.api(name ='myapi',version ='v1',auth = AUTH_CONFIG,...)
class MyApi (remote.service):
...
HTTP_AUTHORIZATION
HTTP_REFERER
HTTP_X_APPENGINE_COUNTRY
HTTP_X_APPENGINE_CITYLATLONG
HTTP_ORIGIN
HTTP_ACCEPT_CHARSET
HTTP_ORIGINALMETHOD
HTTP_X_APPENGINE_REGION
HTTP_X_ORIGIN
HTTP_X_REFERER
HTTP_X_JAVASCRIPT_USER_AGENT
HTTP_ METHOD
HTTP_HOST $ c>
HTTP_CONTENT_TYPE
HTTP_CONTENT_LENGTH
HTTP_X_APPENGINE_PEER
HTTP_ACCEPT $>
HTTP_USER_AGENT
HTTP_X_APPENGINE_CITY
HTTP_X_CLIENTDETAILS
HTTP_ACCEPT_LANGUAGE
class EndpointsAPI(remote.Service):
@endpoints.method(Query_In, Donations_Out, path='get/donations',
http_method='GET', name='get.donations')
def get_donations(self, req):
#Authenticate request via cookie
Query_In
and Donations_Out
are both ProtoRPC messages (messages.Message
). The parameter req
in the function is just an instance of Query_In
and I didn't find any properties related to HTTP data, however I could be wrong.'HTTP_...'
where ...
corresponds to the header name:http = {key: value for key, value in os.environ.iteritems()
if key.lower().startswith('http')}
os.getenv('HTTP_COOKIE')
will give you the header value you seek. Unfortunately, this doesn't get passed along through Google's API Infrastructure by default. from google.appengine.ext.endpoints import api_config
AUTH_CONFIG = api_config.ApiAuth(allow_cookie_auth=True)
@endpoints.api(name='myapi', version='v1', auth=AUTH_CONFIG, ...)
class MyApi(remote.service):
...
HTTP_AUTHORIZATION
HTTP_REFERER
HTTP_X_APPENGINE_COUNTRY
HTTP_X_APPENGINE_CITYLATLONG
HTTP_ORIGIN
HTTP_ACCEPT_CHARSET
HTTP_ORIGINALMETHOD
HTTP_X_APPENGINE_REGION
HTTP_X_ORIGIN
HTTP_X_REFERER
HTTP_X_JAVASCRIPT_USER_AGENT
HTTP_METHOD
HTTP_HOST
HTTP_CONTENT_TYPE
HTTP_CONTENT_LENGTH
HTTP_X_APPENGINE_PEER
HTTP_ACCEPT
HTTP_USER_AGENT
HTTP_X_APPENGINE_CITY
HTTP_X_CLIENTDETAILS
HTTP_ACCEPT_LANGUAGE