Skip to content

Commit

Permalink
Add more username/password pairs.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdemers committed Jan 23, 2014
1 parent 90ee59e commit 6fda43b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions nbviewer/__init__.py
Expand Up @@ -15,23 +15,21 @@
import traceback import traceback


from flask import Flask, jsonify, request from flask import Flask, jsonify, request
from flask.ext.basicauth import BasicAuth
from flask_sslify import SSLify from flask_sslify import SSLify
from werkzeug.exceptions import default_exceptions from werkzeug.exceptions import default_exceptions
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException


from cloudly import logger from cloudly import logger
from cloudly.notify import notify as cloudly_notify from cloudly.notify import notify as cloudly_notify
from nbviewer.metric import evt from nbviewer.metric import evt
from nbviewer.basicauth import MyBasicAuth


FORMAT = "%(asctime)s] %(levelname)s %(module)s %(funcName)s: %(message)s" FORMAT = "%(asctime)s] %(levelname)s %(module)s %(funcName)s: %(message)s"


# The application # The application
app = Flask(__name__) app = Flask(__name__)


# Site-wide basic auth credentials # 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 app.config['BASIC_AUTH_FORCE'] = True


# Debugging # Debugging
Expand All @@ -44,7 +42,7 @@
'oftg09jW2FtbXfcud9OS') 'oftg09jW2FtbXfcud9OS')


# Add basic authentication site-wide. # Add basic authentication site-wide.
basic_auth = BasicAuth(app) basic_auth = MyBasicAuth(app)


# SSLify the app, will redirect all HTTP to HTTPS # SSLify the app, will redirect all HTTP to HTTPS
sslify = SSLify(app) sslify = SSLify(app)
Expand Down
15 changes: 15 additions & 0 deletions 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

0 comments on commit 6fda43b

Please sign in to comment.