0

buddies

One of my GAE restful service needs login with admin account. And I'm writing an automation script in python for testing this service. The script simply do a HTTP POST and then check the returned response. The difficult part for me is how to authenticate the test script as an admin user.

I created an admin account for testing purpose. But I'm not sure how to use that account in my test script. Is there a way that my test script can use oath2 or other approach to authenticate itself as a test admin account?

4

1 回答 1

0

好的,我认为这可能是您正在寻找的,用于身份验证的客户端库,是的,我相信 appengine 现在建议使用 oauth2 进行任何类型的身份验证:

https://developers.google.com/accounts/docs/OAuth2#libraries

然后,您将获得一个身份验证令牌,您可以在其中传递您的宁静请求的标头,例如:

# Your authenticated request
Authorization: Bearer TokenHere

然后在你的处理程序中,你会得到它:

try:
    user = oauth.get_current_user('https://www.googleapis.com/auth/userinfo')
except NotAllowedError:
    user = None

# then from the first link you should be able to access if
user.is_current_user_admin()

这就是我在 android 上进行身份验证的方式,但我只执行一次并将其存储在会话中,然后在 httpclient 上启用 cookie jar。

于 2013-08-02T03:37:42.270 回答