|
7 | 7 | import jwt |
8 | 8 |
|
9 | 9 | from flask_jwt_extended.utils import _encode_access_token, get_jwt_claims, \ |
10 | | - get_jwt_identity, set_refresh_cookies, set_access_cookies |
| 10 | + get_jwt_identity, set_refresh_cookies, set_access_cookies, unset_jwt_cookies |
11 | 11 | from flask_jwt_extended import JWTManager, create_refresh_token, \ |
12 | 12 | jwt_refresh_token_required, create_access_token, fresh_jwt_required, \ |
13 | 13 | jwt_required |
@@ -344,6 +344,12 @@ def login(): |
344 | 344 | set_refresh_cookies(resp, refresh_token) |
345 | 345 | return resp, 200 |
346 | 346 |
|
| 347 | + @self.app.route('/auth/logout', methods=['POST']) |
| 348 | + def logout(): |
| 349 | + resp = jsonify({'logout': True}) |
| 350 | + unset_jwt_cookies(resp) |
| 351 | + return resp, 200 |
| 352 | + |
347 | 353 | @self.app.route('/auth/refresh', methods=['POST']) |
348 | 354 | @jwt_refresh_token_required |
349 | 355 | def refresh(): |
@@ -443,6 +449,13 @@ def test_headers(self): |
443 | 449 | self.assertIn('x_csrf_refresh_token', refresh_csrf) |
444 | 450 | self.assertIn('Path=/', refresh_csrf) |
445 | 451 |
|
| 452 | + # Try logout headers |
| 453 | + resp = self.client.post('/auth/logout') |
| 454 | + refresh_cookie = resp.headers[1][1] |
| 455 | + access_cookie = resp.headers[2][1] |
| 456 | + self.assertIn('Expires=Thu, 01-Jan-1970', refresh_cookie) |
| 457 | + self.assertIn('Expires=Thu, 01-Jan-1970', access_cookie) |
| 458 | + |
446 | 459 | def test_endpoints_with_cookies(self): |
447 | 460 | self.app.config['JWT_COOKIE_CSRF_PROTECT'] = False |
448 | 461 |
|
|
0 commit comments