|
16 | 16 | from flask_ldap3_login import LDAP3LoginManager, AuthenticationResponseStatus |
17 | 17 | from flask_ldap3_login.forms import LDAPLoginForm |
18 | 18 | import i18n |
19 | | -from qwc_services_core.jwt import jwt_manager |
20 | | -from qwc_services_core.auth import GroupNameMapper |
| 19 | +from qwc_services_core.auth import auth_manager, GroupNameMapper, optional_auth |
21 | 20 | from qwc_services_core.runtime_config import RuntimeConfig |
22 | 21 | from qwc_services_core.tenant_handler import ( |
23 | 22 | TenantHandler, TenantPrefixMiddleware, TenantSessionInterface) |
|
32 | 31 | app.config['JWT_ACCESS_TOKEN_EXPIRES'] = int(os.environ.get( |
33 | 32 | 'JWT_ACCESS_TOKEN_EXPIRES', 12*3600)) |
34 | 33 |
|
35 | | -jwt = jwt_manager(app) |
| 34 | +jwt = auth_manager(app) |
36 | 35 | app.secret_key = app.config['JWT_SECRET_KEY'] |
37 | 36 |
|
38 | 37 | i18n.set('load_path', [os.path.join( |
@@ -214,7 +213,14 @@ def login(): |
214 | 213 |
|
215 | 214 | target_url = url_path(request.args.get('url', '/')) |
216 | 215 | if current_user.is_authenticated: |
217 | | - return redirect(target_url) |
| 216 | + if current_user.groups: |
| 217 | + identity = {'username': current_user.username, 'groups': current_user.groups} |
| 218 | + else: |
| 219 | + identity = {'username': current_user.username} |
| 220 | + access_token = create_access_token(identity) |
| 221 | + resp = make_response(redirect(target_url)) |
| 222 | + set_access_cookies(resp, access_token) |
| 223 | + return resp |
218 | 224 | form = LDAPLoginForm(meta=wft_locales()) |
219 | 225 | form.logo = config.get("logo_image_url", {}) |
220 | 226 | form.background = config.get("background_image_url", {}) |
@@ -282,7 +288,7 @@ def verify_login(): |
282 | 288 |
|
283 | 289 |
|
284 | 290 | @app.route('/logout', methods=['GET', 'POST']) |
285 | | -@jwt_required(optional=True) |
| 291 | +@optional_auth |
286 | 292 | def logout(): |
287 | 293 | target_url = url_path(request.args.get('url', '/')) |
288 | 294 | resp = make_response(redirect(target_url)) |
|
0 commit comments