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

[Flask] Not Logged in After Redirect #913

Closed
alviandk opened this issue Apr 25, 2016 · 0 comments
Closed

[Flask] Not Logged in After Redirect #913

alviandk opened this issue Apr 25, 2016 · 0 comments

Comments

@alviandk
Copy link

alviandk commented Apr 25, 2016

I have followed the flask_example with google OAuth2. When I did the authorization, the user successfully made and entered into the database. But after the redirect, the user was not automatically logged in. I combined python-social-auth with flask-security. Can someone help me figure it out where I made a mistake?
This is my implementation in app.py

user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)



engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db_session = scoped_session(Session)
app.register_blueprint(social_auth)
init_social(app, db_session)


login_manager = login.LoginManager()
login_manager.login_view = 'security.login'
login_manager.login_message = ''
login_manager.init_app(app)
@login_manager.user_loader
def load_user(userid):
    return User.query.get(int(userid))



@app.before_request
def global_user():
    g.user = login.current_user


@app.teardown_appcontext
def commit_on_success(error=None):
    if error is None:
        db_session.commit()
    else:
        db_session.rollback()

    db_session.remove()


@app.context_processor
def inject_user():
    try:
        return {'user': g.user}
    except AttributeError:
        return {'user': None}


app.context_processor(backends)
@alviandk alviandk changed the title Not Logged in After Redirect [Flask] Not Logged in After Redirect Apr 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant