Add authentication serializer for Bearer token auth

This commit is contained in:
Georg Krause 2022-07-17 16:36:13 +02:00
parent 2746d8750d
commit fc3fa79e9f
No known key found for this signature in database
GPG Key ID: 2970D504B2183D22
1 changed files with 12 additions and 0 deletions

View File

@ -1,4 +1,5 @@
from drf_spectacular.contrib.django_oauth_toolkit import OpenApiAuthenticationExtension
from drf_spectacular.plumbing import build_bearer_security_scheme_object
import os
@ -28,6 +29,17 @@ class CustomOAuthExt(OpenApiAuthenticationExtension):
return {"type": "oauth2", "flows": flows}
class CustomApplicationTokenExt(OpenApiAuthenticationExtension):
target_class = "funkwhale_api.common.authentication.ApplicationTokenAuthentication"
name = "ApplicationToken"
def get_security_definition(self, auto_schema):
return build_bearer_security_scheme_object(
header_name='Authorization',
token_prefix='Bearer',
)
def custom_preprocessing_hook(endpoints):
filtered = []
# your modifications to the list of operations that are exposed in the schema