Skip to content

Commit

Permalink
Store JWTManager in app.extensions['flask-jwt-extended'] instead of a…
Browse files Browse the repository at this point in the history
…pp.jwt_manager
  • Loading branch information
vimalloc committed Aug 25, 2017
1 parent 018c2fc commit 043ba23
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion flask_jwt_extended/jwt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def init_app(self, app):
:param app: A flask application
"""
# Save this so we can use it later in the extension
app.jwt_manager = self
if not hasattr(app, 'extensions'): # pragma: no cover
app.extensions = {}
app.extensions['flask-jwt-extended'] = self

# Set all the default configurations for this extension
self._set_default_configuration_options(app)
Expand Down
4 changes: 2 additions & 2 deletions flask_jwt_extended/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def decode_token(encoded_token):

def _get_jwt_manager():
try:
return current_app.jwt_manager
except AttributeError: # pragma: no cover
return current_app.extensions['flask-jwt-extended']
except KeyError: # pragma: no cover
raise RuntimeError("You must initialize a JWTManager with this flask "
"application before using this method")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_jwt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def _parse_callback_result(self, result):
def test_init_app(self):
jwt_manager = JWTManager()
jwt_manager.init_app(self.app)
self.assertIsInstance(jwt_manager, JWTManager)
self.assertEqual(jwt_manager, self.app.extensions['flask-jwt-extended'])

def test_class_init(self):
jwt_manager = JWTManager(self.app)
self.assertIsInstance(jwt_manager, JWTManager)
self.assertEqual(jwt_manager, self.app.extensions['flask-jwt-extended'])

def test_default_user_claims_callback(self):
identity = 'foobar'
Expand Down

0 comments on commit 043ba23

Please sign in to comment.