forked from ansible/django-ansible-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding logged basic auth to mimic other apps
Refactoring settings.py to match gateways order for easier reference
- Loading branch information
1 parent
37ba5f4
commit 1337bb4
Showing
3 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logging | ||
|
||
from django.utils.encoding import smart_str | ||
from rest_framework import authentication | ||
|
||
logger = logging.getLogger('test_app.authentication.logged_basic_auth') | ||
|
||
|
||
class LoggedBasicAuthentication(authentication.BasicAuthentication): | ||
def authenticate(self, request): | ||
ret = super(LoggedBasicAuthentication, self).authenticate(request) | ||
if ret: | ||
username = ret[0].username if ret[0] else '<none>' | ||
logger.info(smart_str(f"User {username} performed a {request.method} to {request.path} through the API via basic auth")) | ||
return ret | ||
|
||
def authenticate_header(self, request): | ||
return super(LoggedBasicAuthentication, self).authenticate_header(request) | ||
|
||
|
||
# NOTE: This file is common to many of the services and will allow DRF to return a 401 instead of a 403 on failed login. | ||
# This is the expected behavior we want so we need this file in test_app to mimic other applications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters