使用Python的Google Oauth2.0:如何限制对特定域的访问?

时间:2013-12-09 22:48:50

标签: python google-api oauth-2.0 flask

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

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

1 个答案:

答案 0 :(得分:2)

所以我自己可以回答这个问题。在构建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)               
相关问题