-
I have some code I would like to port to Emmett. In generates and validates a JWT token. I would also add some claims (userinfo) to the token. The code for creating the token is as follows: @action("authenticate", method=['POST'])
Would you mind letting me know how I can check a password against the user password hash in emmett in the standard user / auth table please? Does it also use CRYPT? I have another function that validates the token but maybe I leave this for another discussion. I hope this is not bothering too much, but this is one of the last pieces I need to port an app and get started with Emmett. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@Kkeller83 yes, the code is quite similar, I would write something like this: from emmett import abort, request
from emmett.tools import service
@app.route(methods=["post"])
async def authenticate():
params = await request.params
user = User.get(email=params.email)
if not user or User.password.validate(params.password)[0] != user.password:
abort(403, "error")
return jwt.encode(
{
"username": params.email,
...
},
'secret',
algorithm='HS256'
) |
Beta Was this translation helpful? Give feedback.
@Kkeller83 yes, the code is quite similar, I would write something like this: