In my FLASK app, I need to get the CSRF Token to be able to send a POST request to an endpoint. Let us say the I need the token not in the form but in a python file (for e.g views.py). How do I get the token? I am specifically looking for a function that would return the CSRF token.

This is for logging out scenario. It is required that I send a POST request with JWT Access Token and X-CSRFToken.

@user.route('/logout', methods=['POST'])
@login_required
def logout():
    access_url = '/logout/access'
    access_token = request.cookies.get('access_token_cookie')
    headers = {'Authorization': 'Bearer '+ access_token ,
                'X-CSRFToken': '*******' }
    resp = requests.post(access_url, headers=headers)

I am looking for a function that can provide the value to replace the asterisked block in the code.

0 Answers