audiolion / apistar-jwt

A JSON Web Token Component for API Star
MIT License
41 stars 8 forks source link

Return None instead of raising AuthenticationFailed #8

Closed mshenfield closed 6 years ago

mshenfield commented 6 years ago

Based on the API Star Authorization documentation

An authentication class must implement the authenticate method, and should return a subclass of Auth, or None if the request was not authenticated.

This allows having multiple authentication mechanisms, and to globally set JWTAuthentication in the authentication setting w/out it requiring authorization for every endpoint. Right now, setting

settings = {
    'AUTHENTICATION': [JWTAuthentication()],
}

will 401 if a JWT hasn't been set, which doesn't work well for public endpoints.

Version Info:

Python: 3.6
API Star JWT: 0.2.1
API Star: 0.3.9

Thanks for creating this btw - it's been extremely handy for a side project.

audiolion commented 6 years ago

Ah good point, I will try to get to this on Saturday, if you want to have it earlier feel free to make a PR 👊

mshenfield commented 6 years ago

I can take knock it out in the next day or two.

audiolion commented 6 years ago

it is pretty much just removing the exceptions.py file, and that exception, and returning None instead, updating tests.