question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Give a dictionary to create_access_token

See original GitHub issue

Hey, 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:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
vimalloccommented, Oct 24, 2016

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!

0reactions
laranicolascommented, Oct 24, 2016

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found