Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding optional alt_auth parameter to allow non-HTPASSWD authentication #97

Closed
wants to merge 1 commit into from

Conversation

Tythos
Copy link
Contributor

@Tythos Tythos commented Dec 9, 2015

Added optional alt_auth parameter for specification of authentication mechanism via procedural startup (i.e., init.app). Specifically not enabled for command-line invocation for security purposes. The alt_auth parameter propagates to _app.configure, where it is verified and added to the configuration object (which has been extended to include this field). The config.alt_auth attribute is then invoked (if assigned) in the auth decorator object as a drop-in replacement for _app.validate_user.

This is intended to give administrators the ability to hook in other authentication mechanisms when pypiserver is started procedurally. For example, the following .py file (used with a Passenger configuration) provides a basic .CSV-based method (for demo purposes only), which could just as easily be extended to LDAP or other mechanisms.

from pypiserver import app
import csv

def alt_auth(user, pw):
    with open('users.csv', 'r') as f:
        dr = csv.DictReader(f)
        users = [u for u in dr]
    results = [u['username'] == user and u['password'] == pw for u in users]
    return sum(results) == 1

application = app(root='packages', redirect_to_fallback=False, authenticated=['update'], alt_auth=alt_auth)

@ankostis ankostis added this to the M1.1.9 milestone Dec 19, 2015
@ankostis ankostis self-assigned this Dec 19, 2015
ankostis pushed a commit to ankostis/pypiserver that referenced this pull request Dec 20, 2015
ankostis added a commit to ankostis/pypiserver that referenced this pull request Dec 20, 2015
+ Set Authenticatorfunc on Configure object.
@ankostis ankostis closed this in 101c18f Dec 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants