|
12 | 12 |
|
13 | 13 | from .config import get_runtime_config_private_dict
|
14 | 14 | from .models import db, Role, User
|
15 |
| -from .utils.oauth2 import get_oauth2_identity |
| 15 | +from .utils.oauth2 import get_oauth2_identity, get_oauth2_identity_azure |
16 | 16 |
|
17 | 17 | _logger = logbook.Logger(__name__)
|
18 | 18 |
|
@@ -52,9 +52,15 @@ def login():
|
52 | 52 | return _login_with_credentials(credentials)
|
53 | 53 |
|
54 | 54 | auth_code = credentials.get('authorizationCode')
|
55 |
| - if auth_code: |
| 55 | + provider = credentials.get("provider") |
| 56 | + redirect_uri = credentials.get("redirectUri") |
| 57 | + |
| 58 | + if provider == "google-oauth2": |
56 | 59 | return _login_with_google_oauth2(auth_code)
|
57 | 60 |
|
| 61 | + if provider == "azure-ad2-oauth2": |
| 62 | + return _login_with_azure_oauth2(auth_code, redirect_uri) |
| 63 | + |
58 | 64 | error_abort('No credentials were specified', code=requests.codes.unauthorized)
|
59 | 65 |
|
60 | 66 |
|
@@ -137,6 +143,19 @@ def _login_with_google_oauth2(auth_code):
|
137 | 143 |
|
138 | 144 | return _make_success_login_response(user, user_info)
|
139 | 145 |
|
| 146 | +def _login_with_azure_oauth2(auth_code, redirect_uri): |
| 147 | + """Logs in with azure oath2""" |
| 148 | + user_info = get_oauth2_identity_azure(auth_code, redirect_uri) |
| 149 | + if not user_info: |
| 150 | + error_abort('Could not complete OAuth2 exchange', code=requests.codes.unauthorized) |
| 151 | + |
| 152 | + _check_alowed_email_domain(user_info) |
| 153 | + |
| 154 | + user = get_or_create_user(user_info) |
| 155 | + login_user(user) |
| 156 | + |
| 157 | + return _make_success_login_response(user, user_info) |
| 158 | + |
140 | 159 |
|
141 | 160 | @auth.route("/logout", methods=['POST'])
|
142 | 161 | def logout():
|
|
0 commit comments