docs(api): API Token authentication

!34 #63
This commit is contained in:
2024-06-29 16:24:18 +09:30
parent 111791438a
commit 47d6a3beff
4 changed files with 33 additions and 0 deletions

View File

@ -8,12 +8,31 @@ from api.models.tokens import AuthToken
class TokenAuthentication(BaseAuthentication):
""" API Token Authentication
Provides the ability to use the API by using a token to authenticate.
"""
def authenticate_header(self, request):
return 'Token'
def authenticate(self, request):
""" Authentication the API session using the supplied token
Args:
request (object): API Request Object
Raises:
exceptions.AuthenticationFailed: 'Token header invalid' - Authorization Header Value is not in format `Token <auth-token>`
exceptions.AuthenticationFailed: 'Token header invalid. Possibly incorrectly formatted' - Authentication header value has >1 space
exceptions.AuthenticationFailed: 'Invalid token header. Token string should not contain invalid characters.' - Authorization header contains non-unicode chars
Returns:
None (None): User not authenticated
tuple(user,token): User authenticated
"""
auth = get_authorization_header(request).split()
if not auth:

View File

@ -8,6 +8,7 @@ about: https://gitlab.com/nofusscomputing/infrastructure/configuration-managemen
This section contains the application API documentation to assist in application development. The target audience is anyone whom would be developing the application.
- [Token Authentication](./token_authentication.md)
- [Models](./models/index.md)

View File

@ -0,0 +1,11 @@
---
title: API Token Authentication
description: No Fuss Computings django ITSM API Documentation for API Token Authentication
date: 2024-06-29
template: project.html
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/django_app
---
::: app.api.auth.TokenAuthentication
options:
inherited_members: true

View File

@ -66,6 +66,8 @@ nav:
- projects/django-template/development/api/index.md
- projects/django-template/development/api/token_authentication.md
- Models:
- projects/django-template/development/api/models/index.md