[Python] Flask jwt POST data to endpoint with a token

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    This Flask endpoint is what I am trying hit with Insomnia with a jwt token on a POST:

    @app.route('/', methods=['POST'])
    @token_required
    def json_payloader():

    try:
    some code to do stuff...


    Poking around the internet no matter what I try I always get back a:

    {
    "message": "Token is missing!"
    }


    Bearer authentication token: [​IMG]

    OR with authentication set to None and just trying headers with the token this also fails:

    [​IMG]

    Any tips try greatly appreciated.

    EDIT token_required function

    from flask import Flask, request, jsonify
    import flask
    from flask.helpers import make_response
    import jwt
    from functools import wraps

    def token_required(f):
    @wraps(f)
    def decorated(*args, **kwargs):
    token = request.args.get('token')
    if not token:
    return jsonify({'message': 'Token is missing!'}), 403
    try:
    data = jwt.decode(token, app.config['SECRET_KEY'])
    except:
    return jsonify({'message': 'Token is invalid'}), 403

    return f(*args, **kwargs)
    return decorated

    Continue reading...

Compartilhe esta Página