Merge branch '178-api-documentation' into 'develop'
Resolve "Document important API features" Closes #178 See merge request funkwhale/funkwhale!166
This commit is contained in:
commit
99ff8169fc
13 changed files with 263 additions and 5 deletions
|
|
@ -29,9 +29,6 @@ class TokenHeaderAuth(BaseJSONWebTokenAuthentication):
|
|||
|
||||
|
||||
class TokenAuthMiddleware:
|
||||
"""
|
||||
Custom middleware (insecure) that takes user IDs from the query string.
|
||||
"""
|
||||
|
||||
def __init__(self, inner):
|
||||
# Store the ASGI application we were passed
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
from django.utils.encoding import smart_text
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from rest_framework import exceptions
|
||||
from rest_framework_jwt import authentication
|
||||
from rest_framework_jwt.settings import api_settings
|
||||
|
|
@ -18,3 +21,37 @@ class JSONWebTokenAuthenticationQS(
|
|||
def authenticate_header(self, request):
|
||||
return '{0} realm="{1}"'.format(
|
||||
api_settings.JWT_AUTH_HEADER_PREFIX, self.www_authenticate_realm)
|
||||
|
||||
|
||||
class BearerTokenHeaderAuth(
|
||||
authentication.BaseJSONWebTokenAuthentication):
|
||||
"""
|
||||
For backward compatibility purpose, we used Authorization: JWT <token>
|
||||
but Authorization: Bearer <token> is probably better.
|
||||
"""
|
||||
www_authenticate_realm = 'api'
|
||||
|
||||
def get_jwt_value(self, request):
|
||||
auth = authentication.get_authorization_header(request).split()
|
||||
auth_header_prefix = 'bearer'
|
||||
|
||||
if not auth:
|
||||
if api_settings.JWT_AUTH_COOKIE:
|
||||
return request.COOKIES.get(api_settings.JWT_AUTH_COOKIE)
|
||||
return None
|
||||
|
||||
if smart_text(auth[0].lower()) != auth_header_prefix:
|
||||
return None
|
||||
|
||||
if len(auth) == 1:
|
||||
msg = _('Invalid Authorization header. No credentials provided.')
|
||||
raise exceptions.AuthenticationFailed(msg)
|
||||
elif len(auth) > 2:
|
||||
msg = _('Invalid Authorization header. Credentials string '
|
||||
'should not contain spaces.')
|
||||
raise exceptions.AuthenticationFailed(msg)
|
||||
|
||||
return auth[1]
|
||||
|
||||
def authenticate_header(self, request):
|
||||
return '{0} realm="{1}"'.format('Bearer', self.www_authenticate_realm)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ class ListenableMixin(filters.FilterSet):
|
|||
|
||||
|
||||
class ArtistFilter(ListenableMixin):
|
||||
q = fields.SearchFilter(search_fields=[
|
||||
'name',
|
||||
])
|
||||
|
||||
class Meta:
|
||||
model = models.Artist
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue