Trouble in use with Flask-Login
See original GitHub issueAs far as I can tell, Authomatic doesn’t handle the login/logout, but rather just the initial authorization. So I was presuming to use Flask-Login (+ Flask + SQLAlchemy) to handle this. I finally got it working after some initial issues with SSL (see my other question), and was able to push the creds into the database. The next step was to get the login working, so I was referencing this previous question here: https://github.com/peterhudec/authomatic/issues/1#issuecomment-48904643 . I ended up adding some complexity to it to give better error messages, but between this two things I broke it somehow. Below is my current code in all its glory. I have tried commenting everything out to discover the root of the problem, but I also just get “something went wrong captain”. Side note: is there a good way to debug this? I have it on heroku currently, but I can’t find logs or error messages anywhere.
logger = logging.getLogger('authomatic.core')
logger.addHandler(logging.StreamHandler())
authomatic = FlaskAuthomatic(config=AUTH_CONFIG, secret=SECRET_KEY, debug=True)
@app.route('/login/<provider_name>', methods=['GET', 'POST'])
@authomatic.login('g')
@requires_ssl
def login(provider_name):
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('index'))
if authomatic.result:
if authomatic.result.error:
return 'Something went wrong: {0}'.format(authomatic.result.error.message)
elif authomatic.result.user:
if not (authomatic.result.user.name and authomatic.result.user.id):
update_response = authomatic.result.user.update()
while update_response.status/100 not in [4, 5]:
update_response = authomatic.result.user.update()
if update_response.status/100 in [4, 5]:
return 'Response status: {}'.format(authomatic.response.status)
user = User.query.filter_by(email=authomatic.result.user.email).first()
if user is None:
nickname = authomatic.result.user.name
if nickname is None or nickname == "":
nickname = authomatic.result.user.email.split('@')[0]
nickname = User.make_unique_nickname(nickname)
role = ROLE_USER
if authomatic.result.user.email in PRESET_ADMINS:
role = ROLE_SUPERADMIN
user = User(nickname=authomatic.result.user.name,
email=authomatic.result.user.email,
about_me=authomatic.result.user.id,
role=role,
join=datetime.utcnow(),
last_seen=datetime.utcnow())
db.session.add(user)
db.session.commit()
g.user = user
login_user(g.user, remember=True)
return render_template('result.html', result=authomatic.result)
return authomatic.response
Issue Analytics
- State:
- Created 9 years ago
- Comments:5
Top GitHub Comments
Here is a gist of my working code snippet. I have been busy, but I plan to make a pull request to add a working example using Flask, SQLA, and Flask-Login to the docs
https://gist.github.com/jbolda/b7d344f1f0d1a68f7be8
@jbolda A working example of Authomatic + Flask-Login would be most useful to me. Did you actually get it to work?