[英]Working with OAuth python
I'm am using OAuth to allow my user to OAuth with Hunch, on my webpage I have a button to allow the user to go to Hunch and enter their details 我正在使用OAuth允许我的用户使用Hunch进行OAuth,在我的网页上我有一个按钮,允许用户转到Hunch并输入他们的详细信息
<form action="/hunch" method="post" align = "right">
<div>
<input type="submit" value="Login using Hunch">
</div>
</form>
How can I call a method here rather than a handler? 我怎样才能在这里调用方法而不是处理程序? as it is currently calling this:
因为它目前称之为:
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)
but when I print the url2 it just prints /hunch? 但是当我打印url2时它只是打印/预感? I hope this makes sense.
我希望这是有道理的。
Also should this auth_token_key = self.request.get('auth_token_key')
get information from the url that the user is directed to after they have entered their credentials? 此
auth_token_key = self.request.get('auth_token_key')
应该在用户输入凭据后从用户所指向的网址获取信息?
When GAE (using OpenId) logs in a user, it relies on the /_ah/login_required
page. 当GAE(使用OpenId)登录用户时,它依赖于
/_ah/login_required
页面。
To get a user to enter their own credentials, you should create a page containing links to log in with the different providers you wish to use. 要让用户输入自己的凭据,您应该创建一个页面,其中包含使用您希望使用的不同提供商登录的链接。 You must then override the
/_ah/login_required
mapping in your url mapping file to use your own custom login page rather than the default. 然后,您必须覆盖url映射文件中的
/_ah/login_required
映射,以使用您自己的自定义登录页面而不是默认值。
This is a very good tutorial I used for this. 这是我用于此的非常好的教程。
Google now offers their own official tutorial. 谷歌现在提供自己的官方教程。
Please read the documentation for Hunch OAuth . 请阅读Hunch OAuth的文档。
Rather than intercepting the form on the backend, send the user directly to 而不是截取后端的表单,直接发送给用户
http://hunch.com/authorize/v1/?app_id=12345 (providing your own app_id and an optional next parameter).
http://hunch.com/authorize/v1/?app_id=12345 (提供您自己的app_id和可选的下一个参数)。
If the user authorizes your application, they will be redirected to the redirect_url
registered for your application along with an auth_token_key
. 如果用户授权您的应用程序,他们将被重定向到为您的应用程序注册的
redirect_url
以及auth_token_key
。 For example, an app with a redirect_url
of http://your-domain.com/authorized/ will be redirected to 例如,
redirect_url
为http://your-domain.com/authorized/的应用将被重定向到
http://your-domain.com/authorized/?auth_token_key=7a1b2c3&auth_sig=941bc415af782a8d93a83c874922ae1b30e92a70
http://your-domain.com/authorized/?auth_token_key=7a1b2c3&auth_sig=941bc415af782a8d93a83c874922ae1b30e92a70
At this point you can exchange the auth_token_key
for an auth_token
. 此时,您可以将
auth_token_key
为auth_token
。
The Hunch sample app on Github has an example of how this should be done. Github上的Hunch示例应用程序有一个如何完成此操作的示例。 The
authorize
function generates a page asking the user to Hunch connect, and the authorized
function exchanges the auth_token_key
for an auth_token
. authorize
函数生成一个页面,要求用户进行Hunch连接, authorized
函数将auth_token_key
与auth_token
交换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.