question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable jwt_required for OPTIONS requests

See original GitHub issue

I notice that if a try to protect an entire blueprint with @jwt_required, than also the OPTIONS method is protected.

OPTIONS method should not include crendetials, see here.

The @jwt_required decorator should ignore OPTIONS like in flask_login:

    @wraps(func)
    def decorated_view(*args, **kwargs):
        if request.method in EXEMPT_METHODS:
            return func(*args, **kwargs)
        elif current_app.login_manager._login_disabled:
            return func(*args, **kwargs)
        elif not current_user.is_authenticated:
            return current_app.login_manager.unauthorized()
        return func(*args, **kwargs)
    return decorated_view

where EXEMPT_METHODS=set(["OPTIONS"])!

I could fix this and create a pull request if this is not a desired choice!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ludusrussocommented, Mar 4, 2018

@mgd722 to be honest, I don’t remember why I wrote it… I think I meant that it’s not very clean and maybe it should be more pythonic to explicit it by decorating every route that needs to be protected… What I don’t like too much is to have a “do nothing function” and decorate it…

Anyway, I like that practice and I’ll continue to use it!!

1reaction
vimalloccommented, Feb 9, 2018

Perfect, thanks for all of the information. It sounds like excluding OPTIONS from the jwt_required functions would be the correct thing to do. If you want to submit a pull request I would be happy to get that merged, or I could work on getting that fixed up sometime next week.

Cheers 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Spring Security for OPTIONS Http Method
I am writing a JS client for it and using JQuery to send the GET/POST requests. The application is CORS enabled with this...
Read more >
Configuration Options — flask-jwt-extended 4.4.4 documentation
Cross Site Request Forgery Options: ... The string or list of audiences ( aud ) expected in a JWT when decoding it. Default:...
Read more >
Disable authentication for HTTP OPTIONS method (preflight ...
The only way out seems to be to configure the server to not enforce authentication for HTTP OPTIONS requests. Is there any way...
Read more >
Add an option to disable logging for a specific request
Currently every request created by the rest client code editor is saved to the log. When I need to generate JWT token based...
Read more >
Techniques for bypassing CORS Preflight Requests to ...
If the target server accepts the OPTIONS request and notifies the web ... origin may require two roundtrips: one for the OPTIONS request, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found