Skip to content

Commit

Permalink
Fix rooms not showing behind basic auth
Browse files Browse the repository at this point in the history
This broke rooms on staging. This also appleis to various other
API endpoints, but let's get rooms fixed to start with.
  • Loading branch information
bfirsh authored and jessykate committed Mar 10, 2019
1 parent bd12ea1 commit b78dfa3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions modernomad/middleware/basic_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re
from django.conf import settings
from basicauth.middleware import BasicAuthMiddleware as BaseBasicAuthMiddleware


# https://github.com/hirokiky/django-basicauth/issues/10
class BasicAuthMiddleware(BaseBasicAuthMiddleware):
def process_request(self, request):
always_allow_urls = map(
re.compile, getattr(settings, "BASICAUTH_ALWAYS_ALLOW_URLS", [])
)
for allowed_url in always_allow_urls:
if allowed_url.search(request.path):
return None

return super().process_request(request)
5 changes: 4 additions & 1 deletion modernomad/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

MIDDLEWARE_CLASSES = (
'whitenoise.middleware.WhiteNoiseMiddleware', # first, after SecurityMiddleware
'basicauth.middleware.BasicAuthMiddleware',
'modernomad.middleware.basic_auth.BasicAuthMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down Expand Up @@ -295,6 +295,9 @@ def __getitem__(self, item):
if env('BASICAUTH_USER', default=''):
BASICAUTH_USERS = {}
BASICAUTH_USERS[env('BASICAUTH_USER')] = env('BASICAUTH_PASS')
BASICAUTH_ALWAYS_ALLOW_URLS = [
r'^/graphql'
]
else:
BASICAUTH_DISABLE = True

0 comments on commit b78dfa3

Please sign in to comment.