![]() |
|
Uninitialized ASN.1 value in Flask LDAP3 Auth blueprint - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Uninitialized ASN.1 value in Flask LDAP3 Auth blueprint (/thread-6294.html) |
Uninitialized ASN.1 value in Flask LDAP3 Auth blueprint - zoidberg - Nov-14-2017 I'm trying to put together a flask blueprint for LDAP3 auth. I started out with a standard flask app and that works fine but as soon as I turn it into a blueprint, it fails to work as expected. Here's the debug output when I run the flask app And here's the debug output when run as a blueprintMy __init__.py looks like this:from flask import Flask
app = Flask(__name__)
app.config.from_object('config')
from app.ldauth.views import auth_blueprint
app.register_blueprint(auth_blueprint)And app/ldauth/views.py looks like this:from flask import Flask, Blueprint, url_for
from flask_ldap3_login import LDAP3LoginManager
from flask_login import LoginManager, login_user, UserMixin, current_user
from flask import render_template_string, render_template, redirect
from flask_ldap3_login.forms import LDAPLoginForm
from app import app
auth_blueprint = Blueprint('ldauth',__name__,template_folder='templates')
login_manager = LoginManager(app)
ldap_manager = LDAP3LoginManager(app)
users = {}
class User(UserMixin):
def __init__(self, dn, username, data):
self.dn = dn
self.username = username
self.data = data
def __repr__(self):
return self.dn
def get_id(self):
return self.dn
@login_manager.user_loader
def load_user(id):
if id in users:
return users[id]
return None
@ldap_manager.save_user
def save_user(dn, username, data, memberships):
user = User(dn, username, data)
users[dn] = user
return user
@auth_blueprint.route('/login', methods=['GET', 'POST'])
def login():
template = """
{{ get_flashed_messages() }}
{{ form.errors }}
<form method="POST">
<label>Username{{ form.username() }}</label>
<label>Password{{ form.password() }}</label>
{{ form.submit() }}
{{ form.hidden_tag() }}
</form>
"""
# Instantiate a LDAPLoginForm which has a validator to check if the user
# exists in LDAP.
form = LDAPLoginForm()
if form.validate_on_submit():
# Successfully logged in, We can now access the saved user object
# via form.user.
login_user(form.user) # Tell flask-login to log them in.
# TODO: Validate next to ensure it is safe!
return redirect(next) # Send them home
return render_template_string(template,form=form)Fairly inexperienced with python so maybe I am just doing something fundamentally wrong here. Any suggestions?
RE: Uninitialized ASN.1 value in Flask LDAP3 Auth blueprint - zoidberg - Nov-15-2017 Turns out this was environment related, created a new virtualenv this morning, deployed the code into that and everything is working as expected. |