Give a dictionary to create_access_token
See original GitHub issueHey, would be nice to pass a dictionary value when I’m creating token, so I can use in add_claims_to_access_token and I don’t have to find again to database using identity.
LOGIN: Here I have to find on database.
@custom_api.route('/auth', methods=['POST'])
def login():
options = {
'body': None,
'status_code': 200
}
username = request.json.get('username', None)
password = request.json.get('password', None)
controller = Controller().query.filter_by(uuid=username).first()
if controller and not safe_str_cmp(controller.jwt.encode('utf-8'), password.encode('utf-8')):
raise NotAuthorizedException()
options['body'] = {'access_token': create_access_token(controller)}
return __build_response_msg(options=options)
If not I have to make find twice:
@jwt.user_claims_loader
def add_claims_to_access_token(identity):
controller = Controller().query.filter_by(uuid=identity).first()
return {
'id': controller.id,
'role': controller.role
}
Would be nice to do something like that so I can make a search less:
@jwt.user_claims_loader
def add_claims_to_access_token(identity):
# I can use every parameter from identity dictionary
return {
'id': identity.id,
'role': identity.role
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
dictionary in flask_jwt_extended create_access_token
How can i use dictionary in token identity with flask_jwt_extended. Any suggestions for pass multiple values in token?
Read more >Python create access token - ProgramCreek.com
This page shows Python code examples for create access token.
Read more >corpora.dictionary – Construct word<->id mappings — gensim
This module implements the concept of a Dictionary – a mapping between words and their integer ids. class gensim.corpora.dictionary.
Read more >Token-Based Authentication With Flask - Real Python
This tutorial takes a test-first approach to implementing token-based authentication in a Flask app using JSON Web Tokens (JWTs). Updates:.
Read more >How to create Access Token Using Postman - Adobe Support
Type: OAuth 2.0; Token Name: Provide an intuitive name for the token (stored in Postman). Grant Type: Select Authorization Code.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Awesome, it sounds like we are on the same page then 😃 I’m going to go ahead and close this issue again, I think we should be good now. But if you have any feedback after using it this way for a bit let me know, I would love to hear it.
Thanks!
I’m seeing as a complex way to do a simple thing, would be better to manage from one place, but you already took the decision.
Cheers!