Hi,
in the actual documentation the login_callback does not return, and that seems to cause a lot of problems. While it is ok to just render a template (login_ok) or redirect to '/', a simple decorator could be included in the doc to have a more general case, like:
@sso.login_handler
def login_callback(user_info):
"""Store login information in session."""
session['user'] = user_info
return redirect(request.args.get('next_url'))
def sso_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if 'user' not in session:
return redirect(url_for('sso_login', next_url=request.url))
return f(*args, **kwargs)
return decorated_function
then you can decorate whatever view function that requires authentication with some added value:
- you do not have to actually check for user auth each time
- you can use session['user'] being certain that it will be available
- you'll be redirected to the url you actually asked for
Example:
@app.route('/secure_location')
@sso_required
def secure_location():
return render_template('secure_location.html', user=session['user'])
Hi,
in the actual documentation the
login_callbackdoes not return, and that seems to cause a lot of problems. While it is ok to just render a template (login_ok) or redirect to '/', a simple decorator could be included in the doc to have a more general case, like:then you can decorate whatever view function that requires authentication with some added value:
Example: