How do you restrict Google Login (Oauth2) to emails from a specific Google Apps domain for a Flask WebApp?

后端 未结 2 2017
广开言路
广开言路 2021-02-06 11:29

Developing a Flask app (Python3/Heroku) for internal company use and successfully implemented Google Login (Oauth2) based on brijieshb42\'s article which uses requests_oauthlib.

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 11:35

    When you create the authorization URL, you can append optional parameters; appending hd= ... will do the trick:

    auth_url, state = google.authorization_url(AUTH_URI, access_type='offline', hd='savv.ch')
    

    This has many benefits. For example Google will then automatically pick the right account (if it matches the domain), which potentially saves a step in the Auth process, if the user is logged into multiple accounts.

    http://requests-oauthlib.readthedocs.io/en/latest/api.html#requests_oauthlib.OAuth2Session.authorization_url

提交回复
热议问题