我正在使用 OAuth 来允许我的用户使用 Hunch 进行 OAuth,在我的网页上我有一个按钮允许用户转到 Hunch 并输入他们的详细信息
<form action="/hunch" method="post" align = "right">
<div>
<input type="submit" value="Login using Hunch">
</div>
</form>
我怎样才能在这里调用方法而不是处理程序?正如它目前所说的那样:
class hunch(webapp.RequestHandler):
def post(self):
url = 'http://hunch.com/authorize/v1/?app_id=123&next=/get-recs'
self.redirect(url)
logging.info("url2 = " + url2)
auth_token_key = self.request.get('auth_token_key')
logging.info("auth_token_key = " + auth_token_key)
但是当我打印 url2 时它只打印/hunch?我希望这是有道理的。
此外,此 auth_token_key = self.request.get('auth_token_key')
是否应从用户输入凭据后定向到的 url 获取信息?
最佳答案
请阅读 Hunch OAuth 的文档.
与其在后端拦截表单,不如将用户直接发送到
http://hunch.com/authorize/v1/?app_id=12345 (providing your own app_id and an optional next parameter).
如果用户授权您的应用程序,他们将被重定向到为您的应用程序注册的 redirect_url
以及 auth_token_key
。例如,redirect_url
为 http://your-domain.com/authorized/ 的应用将被重定向到
此时您可以将 auth_token_key
换成 auth_token
。
Hunch sample app on Github有一个应该如何完成的例子。 authorize
函数生成一个页面,要求用户连接 Hunch,authorized
函数将 auth_token_key
换成 auth_token
.
关于python - 使用 OAuth python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4845538/