mor*_*aes 5 google-app-engine provisioning google-apps google-apps-marketplace
我正在尝试在从Google Apps市场安装的应用中检查用户是否是其Google Apps域的管理员.
我把它添加到manifest.xml:
<Scope id="Provisioning API">
<Url>https://apps-apis.google.com/a/feeds/user/#readonly</Url>
<Reason>This application can list domain users to give them permissions.</Reason>
</Scope>
Run Code Online (Sandbox Code Playgroud)
然后我设置一个测试处理程序让它工作:
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
import gdata.alt.appengine
import gdata.apps.service
import gdata.auth
# App id, key and secret from the Google Apps Marketplace.
APPLICATION_ID = 'XXX'
CONSUMER_KEY = 'XXX'
CONSUMER_SECRET = 'XXX'
class SetupHandler(webapp.RequestHandler):
def get(self, *args):
# The domain where this app is installed.
domain = 'my_customer_domain.com'
# A username to check.
username = 'webmaster'
sig_method = gdata.auth.OAuthSignatureMethod.HMAC_SHA1
service = gdata.apps.service.AppsService(source='tipfy-com',
domain=domain)
service.SetOAuthInputParameters(sig_method, CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
two_legged_oauth=True,
requestor_id=APPLICATION_ID)
service.ssl = True
service.debug = True
gdata.alt.appengine.run_on_appengine(service)
lookup_user = service.RetrieveUser(username)
if lookup_user.login.admin == 'true':
res = username + ' is an admin.'
else:
res = username + ' is not an admin.'
self.response.out.write(res)
app = webapp.WSGIApplication([
('/.*', SetupHandler),
], debug=True)
def main():
util.run_wsgi_app(app)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
但是我收到401响应("未知授权标题").我不知道我做错了什么或如何进一步调试它.
user.email()
是否可以获取用户的用户名和域名?(我调试它,并在我的情况是:我得到了"站长"和"example.com",这是在已安装应用程序的用户和谷歌Apps域).我错过了什么?
编辑:由于某种原因,管理面板未请求权限授予对提供的范围的访问权限.在我授予它之后,上面的代码工作了.所以把它作为一个工作的例子吧!
您不必为范围工作重新添加应用程序,只需确保在 GoogleApps 管理信息中心的应用程序设置中,您“授予访问权限”并且数据访问权限为“已授予”。否则只需授予该访问权限。
拆分user.email()
对我来说就像一个魅力,因为user.nickname()
在本地主机测试中包含完整的电子邮件,而不是像生产(其中包含用户名)。
确保请求的用户是管理员。
归档时间: |
|
查看次数: |
1355 次 |
最近记录: |