add api key auth to swagger
This commit is contained in:
@@ -2,4 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from .celery import app as celery_app
|
||||
|
||||
# drf auto-registers this as an authentication method when imported
|
||||
from .schema import APIAuthenticationScheme
|
||||
|
||||
__all__ = ("celery_app",)
|
||||
|
||||
12
api/tacticalrmm/tacticalrmm/schema.py
Normal file
12
api/tacticalrmm/tacticalrmm/schema.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from drf_spectacular.extensions import OpenApiAuthenticationExtension
|
||||
|
||||
# custom api key auth for swagger-ui
|
||||
class APIAuthenticationScheme(OpenApiAuthenticationExtension):
|
||||
target_class = "tacticalrmm.auth.APIAuthentication" # full import path OR class ref
|
||||
name = 'API Key Auth' # name used in the schem
|
||||
def get_security_definition(self, auto_schema):
|
||||
return {
|
||||
'type': 'apiKey',
|
||||
'in': 'header',
|
||||
'name': 'X-API-KEY',
|
||||
}
|
||||
@@ -58,7 +58,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
"DATETIME_FORMAT": "%b-%d-%Y - %H:%M",
|
||||
# "DATETIME_FORMAT": "%b-%d-%Y - %H:%M",
|
||||
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
|
||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||
"knox.auth.TokenAuthentication",
|
||||
@@ -71,6 +71,7 @@ SPECTACULAR_SETTINGS = {
|
||||
"TITLE": "Tactical RMM API",
|
||||
"DESCRIPTION": "Simple and Fast remote monitoring and management tool",
|
||||
"VERSION": TRMM_VERSION,
|
||||
'AUTHENTICATION_WHITELIST': ["tacticalrmm.auth.APIAuthentication"],
|
||||
}
|
||||
|
||||
if not "AZPIPELINE" in os.environ:
|
||||
|
||||
Reference in New Issue
Block a user