使用Python的Google Oauth2.0:如何限制对特定域的访问? [英] Google Oauth2.0 with Python: How do I limit access to a specific domain?

查看:165
本文介绍了使用Python的Google Oauth2.0:如何限制对特定域的访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何在使用这个Python Oauth2.0示例时限制对我的应用程序的访问。我已经看到了你可以添加一个hd = domain.com到一个authorize_url的结尾的地方,但是这对我不起作用。

任何人都可以根据这个例子阐明如何限制访问我的烧瓶应用程序吗?
https://github.com/mitsuhiko/flask -oauth / blob / master / example / google.py

解决方案

当建立谷歌对象的高清参数应该像这样添加。

  google = oauth.remote_app('google',
ase_url ='https://www.google.com / accounts /',
authorize_url ='https://accounts.google.com/o/oauth2/auth',
request_token_url = None,
request_token_params = {'scope':'https ://www.googleapis.com/auth/userinfo.email',
'response_type':'code',
'hd':'domain.com'},
access_token_url =' https://accounts.google.com/o/oauth2/token',
access_token_method ='POST',
access_token_params = {'grant_type':'authorization_code'},
consumer_key = GOOGLE_CLIENT_ID ,
consumer_secret = GOOGLE_CLIENT_SECRET)


I'm trying to understand how to limit access to my application when using this Python Oauth2.0 example. I've seen places where you can add an hd=domain.com to the end of an authorize_url but that doesn't work for me.

Can anyone shed some light on how to limit access to my flask app based on this example? https://github.com/mitsuhiko/flask-oauth/blob/master/example/google.py

解决方案

So I can answer this myself. When building the google object the 'hd' param should be added as such.

google = oauth.remote_app('google',
                      base_url='https://www.google.com/accounts/',
                      authorize_url='https://accounts.google.com/o/oauth2/auth',
                      request_token_url=None,
                      request_token_params={'scope': 'https://www.googleapis.com/auth/userinfo.email',
                                            'response_type': 'code',
                                            'hd':'domain.com'},
                      access_token_url='https://accounts.google.com/o/oauth2/token',
                      access_token_method='POST',
                      access_token_params={'grant_type': 'authorization_code'},
                      consumer_key=GOOGLE_CLIENT_ID,
                      consumer_secret=GOOGLE_CLIENT_SECRET)               

这篇关于使用Python的Google Oauth2.0:如何限制对特定域的访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆