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

Payload callback #102

Open
laranicolas opened this issue Oct 15, 2016 · 9 comments
Open

Payload callback #102

laranicolas opened this issue Oct 15, 2016 · 9 comments

Comments

@laranicolas
Copy link

Hey, I'm trying to overwrite the default payload_callback but I can't, what I'm doing wrong?

@jwt.jwt_payload_callback
def make_payload(u):
    print "YEAH"
    print "YEAH"
    iat = datetime.utcnow()
    exp = iat + timedelta(seconds=60)
    nbf = iat + timedelta(seconds=0)
    return {'iat': iat, 'exp': exp, 'nbf': nbf, 'id': u.id, 'role': u.role}

I would expect to see in payload next result:

{'iat': iat, 'exp': exp, 'nbf': nbf, 'id': u.id, 'role': u.role}

@vimalloc
Copy link

Looking at the default payload creating method, it looks like it expects 'identity' instead of 'id' for the key. That might be the problem.

Alternatively, perhaps checkout flask-jwt-extended. It's designed to make a few things llke this easier to do: http://flask-jwt-extended.readthedocs.io/en/latest/add_custom_data_claims.html (I am the author of that extension).

Hope this helps!

@laranicolas
Copy link
Author

Hey thanks for answer!

But I never see on the console the string print YEAH, could be decorator not be working?

Other things are working correctly, but I want to overwrite the payload.

jwt = JWT(app, authenticate, identity)

@jwt.jwt_payload_callback
def make_payload(u):
    print "YEAH"
    print "YEAH"
    iat = datetime.utcnow()
    exp = iat + timedelta(seconds=60)
    nbf = iat + timedelta(seconds=0)
   return {'iat': iat, 'exp': exp, 'nbf': nbf, 'id': u.id, 'role': u.role}

@vimalloc
Copy link

I think you need to change it from jwt_payload_callback to
jwt_payload_handler.

On Oct 15, 2016 11:20 AM, "Nicolás Lara" [email protected] wrote:

Hey thanks for answer!

But I never see on the console the string print YEAH, could be decorator
not be working?

Other things are working correctly, but I want to overwrite the payload.

jwt = JWT(app, authenticate, identity)

@jwt.jwt_payload_callback
def make_payload(u):
print "YEAH"
print "YEAH"
iat = datetime.utcnow()
exp = iat + timedelta(seconds=60)
nbf = iat + timedelta(seconds=0)
return {'iat': iat, 'exp': exp, 'nbf': nbf, 'id': u.id, 'role': u.role}


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#102 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAOlVfSCqlfGoPN2BENniLiM-5FqGMexks5q0QttgaJpZM4KXsxs
.

@laranicolas
Copy link
Author

Sorry, yes I'm using @jwt.jwt_payload_handler, but also is not working, any idea?

@vimalloc
Copy link

I dont, sorry. It's been a while since I used this library, and with all the open issues and pull requests it looks like it isn't being maintained at the moment either, which is why I made the flask_jwt_extended library. If you end up trying the flask_jwt_extended library and had issues there I would be able to help further.

Best of luck getting this working, the source code for this library isn't very big, so perhaps looking though it you could find your answer.

@laranicolas
Copy link
Author

Thanks anyway for the predisposition to answer. I already see the code, but for the moment I didn't see a decorator for jwt_payload_hanlder, I will continue debugging if couldn't I will try to use your extension!

@laranicolas
Copy link
Author

@vimalloc I will remove flask-jwt use your extension!

@vimalloc
Copy link

I hope it helps you out :) It's still a relatively new extension, so if you run into any oddities, issues, or missing features, please let me know.

@laranicolas
Copy link
Author

I just found an issue, I will write you on flask_jwt_extended github.

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

No branches or pull requests

2 participants