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

Conversation

@ex5
Copy link

@ex5 ex5 commented Jul 26, 2017

looking at the code, it seems like a dict identity should work, but it requires a small fix:

  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
    return original_handler(e)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_jwt/__init__.py", line 127, in _default_auth_request_handler
    access_token = _jwt.jwt_encode_callback(identity)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_jwt/__init__.py", line 62, in _default_jwt_encode_handler
    payload = _jwt.jwt_payload_callback(identity)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_jwt/__init__.py", line 53, in _default_jwt_payload_handler
    identity = getattr(identity, 'id') or identity['id']
AttributeError: 'dict' object has no attribute 'id'

looking at the code, it seems like a dict `identity` should work, but it requires a small fix:

```python
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_restful/__init__.py", line 273, in error_router
    return original_handler(e)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_jwt/__init__.py", line 127, in _default_auth_request_handler
    access_token = _jwt.jwt_encode_callback(identity)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_jwt/__init__.py", line 62, in _default_jwt_encode_handler
    payload = _jwt.jwt_payload_callback(identity)
  File "/home/anka/envs/modelrepository/lib/python3.6/site-packages/flask_jwt/__init__.py", line 53, in _default_jwt_payload_handler
    identity = getattr(identity, 'id') or identity['id']
AttributeError: 'dict' object has no attribute 'id'
```
@vimalloc
Copy link

vimalloc commented Jul 26, 2017

Addressed in #63 as well. This project has long been abandoned for a long time, that pr has been open for a year and a half. Perhaps check out flask-jwt-extended, it gives you more flexibility and is still maintained (full disclosure, I'm the author of that extension).

@ex5
Copy link
Author

ex5 commented Jul 26, 2017

@vimalloc oh, forgot to look through the issues, sorry.
I've actually checked flask-jwt-extended out first and had to go with this one because flask-jwt-extended enforces presence of jti and type keys, and that doesn't work with third party generated tokens that happen not to have them

@ex5 ex5 closed this Jul 26, 2017
@vimalloc
Copy link

That makes sense :) Perhaps check out pyjwt directly? The API is pretty simple, and you could rip the jwt_required decorator from this extension. Good luck either way.

@ex5
Copy link
Author

ex5 commented Jul 26, 2017

yeah, using pyjwt directly makes more sense in this case

thanks! =]

@vimalloc
Copy link

In case you are still interested in this, or someone else stumbles upon this, let me introduce Flask-JWT-Simple (https://github.com/vimalloc/flask-jwt-simple). It is a toned down version of Flask-JWT-Extended with all the opinionated stuff needed for the extra features ripped out. This new extension allow you full control over claims when creating JWTs, and places no restrictions on what claims need to be in consumed JWTs.

If there are features missing from the simple variant of this extension that you would like to see, I would be more then happy to port them over. The two that I could see being helpful right off hand is JWT blacklisting and JWT claim verification.

Cheers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants