-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathauthentication.py
37 lines (28 loc) · 1.02 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
from drf_spectacular.extensions import OpenApiAuthenticationExtension
class SessionScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework.authentication.SessionAuthentication'
name = 'cookieAuth'
def get_security_definition(self, auto_schema):
return {
'type': 'apiKey',
'in': 'cookie',
'name': 'Session',
}
class BasicScheme(OpenApiAuthenticationExtension):
target_class = 'rest_framework.authentication.BasicAuthentication'
name = 'basicAuth'
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
def get_security_definition(self, auto_schema):
return {
'type': 'http',
'scheme': 'bearer',
'bearerFormat': self.target.keyword,
}