我正在 GAE(谷歌应用引擎)上开发一个应用程序。该应用程序是一个聊天机器人,用户可以使用它来访问一些资源。问题是,我不希望任何知道应用程序 ID 的用户都可以将该聊天机器人添加到他们的联系人中,因为它管理私有(private)信息,因此我只想限制我的域帐户的访问权限。我阅读了 GAE 文档并发现了这个(https://developers.google.com/appengine/docs/python/xmpp/overview#Handling_Subscriptions),但我真的不知道如何应用它。我做了这样的事情:
class SuscribeHandler(webapp.RequestHandler):
def post(self):
sender = self.request.get('from').split('/')[0]
domain = sender.split("@")[1]
if domain == "mydomain.com":
#Add contact code goes here
app = webapp.WSGIApplication([
('/_ah/xmpp/subscription/subscribe/', SuscribeHandler),
], debug=True)
最佳答案
您无法阻止用户将您的机器人添加到名册中。根据 XMPP 文档:
App Engine accepts all chat invitations and automatically registers subscriptions as described in the Handling Subscriptions section. App Engine routes all chat messages to the application, regardless of whether the sender previously sent an invitation to the app.
您应该拒绝回复来自未经授权使用您的应用程序的用户的消息。
关于python - 拒绝订阅 Google App Engine 上具有不同域的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12218216/