Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Returned support for JWT_AUTH_ENDPOINT #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flask_jwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,17 @@ def init_app(self, app):
app.config.setdefault('JWT_SECRET_KEY', app.config['SECRET_KEY'])

auth_url_rule = app.config.get('JWT_AUTH_URL_RULE', None)
endpoint = app.config.get('JWT_AUTH_ENDPOINT', None)

if auth_url_rule:
if auth_url_rule and endpoint:
if self.auth_request_callback == _default_auth_request_handler:
assert self.authentication_callback is not None, (
'an authentication_handler function must be defined when using the built in '
'authentication resource')

auth_url_options = app.config.get('JWT_AUTH_URL_OPTIONS', {'methods': ['POST']})
auth_url_options.setdefault('view_func', self.auth_request_callback)
auth_url_options.setdefault('endpoint', endpoint)
app.add_url_rule(auth_url_rule, **auth_url_options)

app.errorhandler(JWTError)(self._jwt_error_callback)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def test_adds_auth_endpoint():
app.config['JWT_AUTH_ENDPOINT'] = 'jwt_auth'
flask_jwt.JWT(app, lambda: None, lambda: None)
rules = [str(r) for r in app.url_map._rules]
endpoints = [r.endpoint for r in app.url_map.iter_rules()]
assert '/auth' in rules
assert 'jwt_auth' in endpoints


def test_auth_endpoint_with_valid_request(client, user):
Expand Down