在 App Engine 上进行身份验证后无法获取 GData 的身份验证令牌
我想提取 Gdata 身份验证的身份验证令牌,以便我可以写入谷歌日历。我在身份验证后获取令牌时遇到问题,以便我可以将令牌发送到日历服务。
我正在使用 appengine 提供的默认登录屏幕 (/_ah/login),并且能够登录并进行身份验证,但是,我无法从 self.request.uri 中提取身份验证令牌,因为 URL 正在被重写:
示例:
从 Kiddushfund.appspot.com/admin 重定向登录屏幕 https://www.google.com/accounts/ServiceLogin?service=ah&continue=http://appname。 appspot.com/_ah/login%3Fcontinue%3Dhttp://appname.appspot.com/admin<mpl=gm&ahname=App+Name&sig=65e70293a754da54fe06ecbedbb59213
这是身份验证后的最终 URL,但我我无法再提取令牌 http://appname.appspot.com/admin
这似乎是一个非常简单的问题,任何帮助都会受到赞赏。谢谢。
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
from google.appengine.ext import webapp
import atom
import settings
import os
import urllib
import urllib2
import cookielib
import gdata.service
import gdata.auth
import gdata.alt.appengine
import gdata.calendar
import gdata.calendar.service
class Auth(webapp.RequestHandler):
def __init__(self):
self.calendar_client = gdata.calendar.service.CalendarService()
gdata.alt.appengine.run_on_appengine(self.calendar_client)
def get(self):
user = users.get_current_user()
if user:
token_request_url = None
auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
if auth_token:
self.calendar_client.SetAuthSubToken(self.calendar_client.upgrade_to_session_token(auth_token))
if not isinstance(self.calendar_client.token_store.find_token(
'http://www.google.com/calendar/feeds/'),gdata.auth.AuthSubToken):
token_request_url = gdata.auth.generate_auth_sub_url(self.request.uri,
('http://www.google.com/calendar/feeds/default/',))
#This is where I were I would look for the token but the self.request.url
# is only return http://appname.appspot.admin - with no token.
self.response.out.write(self.request.uri)
else:
self.redirect(users.create_login_url(self.request.uri))
def main():
application = webapp.WSGIApplication([('/.*', Auth),], debug=True)
run_wsgi_app(application)
if __name__ == '__main__':
main()
I would like to pull the Auth Token for the Gdata auth so that I can write to a google calendar. I am having issues getting the token after authentication so that I can send the token to the calendar service.
I am using the default login screen provided by appengine (/_ah/login) and I am able to login and authenticate, however, I am unable to pull the Auth Token out of the self.request.uri because the URL is being rewritten:
Example:
Login Screen Redirect from kiddushfund.appspot.com/admin
https://www.google.com/accounts/ServiceLogin?service=ah&continue=http://appname.appspot.com/_ah/login%3Fcontinue%3Dhttp://appname.appspot.com/admin<mpl=gm&ahname=App+Name&sig=65e70293a754da54fe06ecbedbb59213
This is after authentication and the URL was pulled out of firebug
http://appname.appspot.com/_ah/login?continue=http://appname.appspot.com/admin&auth=DQAAAL0AAAD9X_Noig8blUlg_KA02UbjgBC2yWl8XKXIVA3SI5ZQ7pJOyL4SyYPpKu5jOLAw0ol0rSUVBENBMmWC2DkH6sTxx3AlSF4UI_LcByDlacBV3Fy1At80h_ML97fLeu0LLQbgzuLxY_wTHBb5svkCVDOeVABFKf98qvZ62SGl0PrDTxs1P3lCF04ooDdFilDecGUoED6hbnjd9P7-6eqxOO9nrBCSk571uyWZCLIA-1I5f3Om_MqAIPmi_5mqLXOSv0I
This is the final URL after the authentication but I'm not able to pull the token anymore
http://appname.appspot.com/admin
This seems like a really simple problem and any help would be appreciated. Thanks.
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
from google.appengine.ext import webapp
import atom
import settings
import os
import urllib
import urllib2
import cookielib
import gdata.service
import gdata.auth
import gdata.alt.appengine
import gdata.calendar
import gdata.calendar.service
class Auth(webapp.RequestHandler):
def __init__(self):
self.calendar_client = gdata.calendar.service.CalendarService()
gdata.alt.appengine.run_on_appengine(self.calendar_client)
def get(self):
user = users.get_current_user()
if user:
token_request_url = None
auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
if auth_token:
self.calendar_client.SetAuthSubToken(self.calendar_client.upgrade_to_session_token(auth_token))
if not isinstance(self.calendar_client.token_store.find_token(
'http://www.google.com/calendar/feeds/'),gdata.auth.AuthSubToken):
token_request_url = gdata.auth.generate_auth_sub_url(self.request.uri,
('http://www.google.com/calendar/feeds/default/',))
#This is where I were I would look for the token but the self.request.url
# is only return http://appname.appspot.admin - with no token.
self.response.out.write(self.request.uri)
else:
self.redirect(users.create_login_url(self.request.uri))
def main():
application = webapp.WSGIApplication([('/.*', Auth),], debug=True)
run_wsgi_app(application)
if __name__ == '__main__':
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
登录屏幕仅向您的应用程序验证用户身份,不会向您授予对用户 gdata 的授权。
您需要让用户授权您使用日历 api - 我建议通过此处的 oauth:http://code.google.com/apis/gdata/docs/auth/overview.html#OAuth。
您只需执行一次此操作,然后存储该用户的 oauth 令牌以用于所有后续调用。
The login screen only authenticates the user to your application, it does not give you authorization to the user's gdata.
You will need to have the user authorize your use of the calendar api - I suggest through oauth here: http://code.google.com/apis/gdata/docs/auth/overview.html#OAuth.
You only need to do this once, and then store the oauth token for that user for all subsequent calls.
未偿还代币的数量存在限制——例如可能的用户数量。未偿还的 ClientLogin 令牌数量如何?
There are limitations about number of tokens outstanding - e.g. numbers of users possible. What about number of ClientLogin tokens outstanding?