-
Notifications
You must be signed in to change notification settings - Fork 270
/
authentication.py
42 lines (32 loc) · 1.21 KB
/
authentication.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from django.conf import settings
from drf_spectacular.extensions import OpenApiAuthenticationExtension
from drf_spectacular.plumbing import build_bearer_security_scheme_object
class SessionScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework.authentication.SessionAuthentication'
name = 'cookieAuth'
priority = -1
def get_security_definition(self, auto_schema):
return {
'type': 'apiKey',
'in': 'cookie',
'name': settings.SESSION_COOKIE_NAME,
}
class BasicScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework.authentication.BasicAuthentication'
name = 'basicAuth'
priority = -1
def get_security_definition(self, auto_schema):
return {
'type': 'http',
'scheme': 'basic',
}
class TokenScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework.authentication.TokenAuthentication'
name = 'tokenAuth'
match_subclasses = True
priority = -1
def get_security_definition(self, auto_schema):
return build_bearer_security_scheme_object(
header_name='Authorization',
token_prefix=self.target.keyword,
)