Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python /Flask Login with LDAP Auth
#1
I have Python/Flask application with a login screen. My goal is to utilize LDAP authentication in unison with my Python/Flask app.

The issue that i am running into is this: " raise RuntimeError('The session is unavailable because no secret ' RuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret." I have a secret key and i still get the error same error when i comment it out.

Here is my code:
import token
from flask import Flask, session
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager

app = Flask(name)
app.secret_key = 'welfhwdlhwdlfhwelfhwlehfwlehfelwehflwefwlehflwefhlwefhlewjfhwelfjhweflhweflhwel'
app.config['SESSION_TYPE'] = 'filesystem'
app.config['LDAP_AUTH_SERVER'] = 'LDAPLocation.com'
app.config['LDAP_PORT'] = '636'
app.config['LDAP_TOP_DN'] = 'CN=something here,OU=somethingHere,OU=SomeService Accounts,dc=magic,dc=pumpum,DC=com Xe'
app.config['LDAP_BIND_USER_PASSWORD'] = 'pssword'
app.register_blueprint(token, url_prefix='/auth')

db = SQLAlchemy(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

from app.auth.views import auth

app.register_blueprint(auth)

Thank you in advance....
Quote
#2
What's the whole traceback message?
It's dangerous to go alone!  Take this: https://docs.python.org/3/library/index.html

Currently #4 in both post count, and rep. wavic and buran, I'm coming for you...
Quote
#3
see reply
Quote
#4
(Apr-16-2018, 12:35 PM)pythonnubie Wrote: see reply

Traceback (most recent call last):
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\e751975\PythonApp\venv\login\app.py", line 21, in do_admin_login
flash('wrong password!')
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\helpers.py", line 387, in flash
session['_flashes'] = flashes
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\werkzeug\local.py", line 350, in __setitem__
self._get_current_object()[key] = value
File "C:\Users\e751975\PythonApp\venv\lib\site-packages\flask\sessions.py", line 130, in _fail
raise RuntimeError('The session is unavailable because no secret '
RuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
Quote
#5
Alright, after looking through the source, it looks like the LoginManager doesn't actually manage the session itself, it only adds some things on top of it. So you still need to let Flask know what sort of session management you're using.

https://github.com/pallets/flask/blob/ma...ns.py#L124 Wrote:If :meth:open_session returns None Flask will call into
:meth:make_null_session to create a session that acts as replacement
if the session support cannot work because some requirement is not
fulfilled. The default :class:NullSession class that is created
will complain that the secret key was not set.

To replace the session interface on an application all you have to do
is to assign :attr:flask.Flask.session_interface::
app = Flask(__name__)
app.session_interface = MySessionInterface()
That's the error you're getting, which leads me to believe this is an easy fix.

After you create your app, but before running it, try adding this line, and let's see if that fixes it (or at least gives a different error): app.session_interface = session.SecureCookieSessionInterface()
It's dangerous to go alone!  Take this: https://docs.python.org/3/library/index.html

Currently #4 in both post count, and rep. wavic and buran, I'm coming for you...
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Redirecting all Flask logs georgelza 0 34 Apr-18-2018, 12:48 PM
Last Post: georgelza
  flask, I want to send a json from the front end and update it to the postgresql DB wi passion044 1 89 Apr-12-2018, 08:40 AM
Last Post: thomasp
  Flask - Opening second page via href is failing - This site can’t be reached rafiPython1 2 69 Apr-11-2018, 08:41 AM
Last Post: rafiPython1
  popup login form in django uditvashisht 0 328 Jan-31-2018, 11:55 PM
Last Post: uditvashisht
  General advice web application - flask - database - cms bashage 6 383 Jan-31-2018, 06:07 PM
Last Post: frostbite
  python3 + Flask + SQLite = HTTP 400 supertoy 5 319 Jan-30-2018, 02:13 PM
Last Post: supertoy
  Home / Login & Logout Page ab_1986 1 232 Dec-20-2017, 06:26 AM
Last Post: Larz60+
  Uninitialized ASN.1 value in Flask LDAP3 Auth blueprint zoidberg 1 345 Nov-15-2017, 12:29 PM
Last Post: zoidberg
  show csv file in flask template.html rr28rizal 5 2,805 Nov-12-2017, 01:53 PM
Last Post: rr28rizal
  Insert data to SQL through pymysql and flask iainstott 3 800 Oct-24-2017, 03:04 PM
Last Post: iainstott

Forum Jump:


Users browsing this thread: 1 Guest(s)