Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add more username/password pairs.

  • Loading branch information...
commit 6fda43b4e017e72620289dc30ed23f2c7f7ef955 1 parent 90ee59e
@hdemers hdemers authored
Showing with 17 additions and 4 deletions.
  1. +2 −4 nbviewer/__init__.py
  2. +15 −0 nbviewer/basicauth.py
View
6 nbviewer/__init__.py
@@ -15,7 +15,6 @@
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
@@ -23,6 +22,7 @@
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"
@@ -30,8 +30,6 @@
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
15 nbviewer/basicauth.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.