带有Python的Google Oauth2.0:如何限制对特定域的访问?
问题内容:
我试图了解使用此Python Oauth2.0示例时如何限制对我的应用程序的访问。我见过一些可以将hd =
domain.com添加到authorize_url末尾的地方,但这对我不起作用。
有人可以根据此示例阐明如何限制对我的Flask应用程序的访问吗? https://github.com/mitsuhiko/flask-
oauth/blob/master/example/google.py
问题答案:
所以我可以自己回答。在构建google对象时,应将“ hd”参数添加为此类。
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)