Permalink
Browse files

Merge pull request #2 from ooda/more-credentials

Add more username/password pairs.
  • Loading branch information...
2 parents 90ee59e + 6fda43b commit 75fb993948f55cf839c24695f67c5cb40be17324 @hdemers hdemers committed Jan 23, 2014
Showing with 17 additions and 4 deletions.
  1. +2 −4 nbviewer/__init__.py
  2. +15 −0 nbviewer/basicauth.py
View
@@ -15,23 +15,21 @@
import traceback
from flask import Flask, jsonify, request
-from flask.ext.basicauth import BasicAuth
from flask_sslify import SSLify
from werkzeug.exceptions import default_exceptions
from werkzeug.exceptions import HTTPException
from cloudly import logger
from cloudly.notify import notify as cloudly_notify
from nbviewer.metric import evt
+from nbviewer.basicauth import MyBasicAuth
FORMAT = "%(asctime)s] %(levelname)s %(module)s %(funcName)s: %(message)s"
# The application
app = Flask(__name__)
# Site-wide basic auth credentials
-app.config['BASIC_AUTH_USERNAME'] = os.environ.get("NBVIEWER_USERNAME")
-app.config['BASIC_AUTH_PASSWORD'] = os.environ.get("NBVIEWER_PASSWORD")
app.config['BASIC_AUTH_FORCE'] = True
# Debugging
@@ -44,7 +42,7 @@
'oftg09jW2FtbXfcud9OS')
# Add basic authentication site-wide.
-basic_auth = BasicAuth(app)
+basic_auth = MyBasicAuth(app)
# SSLify the app, will redirect all HTTP to HTTPS
sslify = SSLify(app)
View
@@ -0,0 +1,15 @@
+import os
+
+from flask.ext.basicauth import BasicAuth
+
+
+class MyBasicAuth(BasicAuth):
+ def __init__(self, app=None):
+ super(MyBasicAuth, self).__init__(app)
+
+ def check_credentials(self, username, password):
+ usernames = os.environ.get("NBVIEWER_USERNAMES", '').split('/')
+ passwords = os.environ.get("NBVIEWER_PASSWORDS", '').split('/')
+
+ creds = {u: p for u, p in zip(usernames, passwords)}
+ return username in creds and creds[username] == password

0 comments on commit 75fb993

Please sign in to comment.