Skip to content

Generating a JWT Token in Emmett #331

Answered by gi0baro
KellerKev asked this question in Q&A
Discussion options

You must be logged in to vote

@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'
    )

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KellerKev
Comment options

Answer selected by KellerKev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants