1

Flask-Dance cannot add entries more than 1. This also causes people to login into others accounts. This is how the db looks like all the time:

enter image description here

We are using sqlalchemy to cache user logins.

dbsl = SQLAlchemy()

d_oauth = discord_oauth.make_discord_blueprint(
    client_id="id",
    client_secret="secret",
    scope=["guilds", "identify"],
    redirect_to="index",
    login_url="/",
    authorized_url="/authorized"
)


class OAuth(OAuthConsumerMixin, dbsl.Model):
    pass


d_oauth.storage = SQLAlchemyStorage(OAuth, dbsl.session)
dbsl.create_all()

This is our Flask app:

def create_app():
    app_db = Flask(__name__)

    app_db.config["SECRET_KEY"] = "please-work"
    app_db.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///configs/cache.sqlite3"
    app_db.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app_db.config["SESSION_TYPE"] = "sqlalchemy"
    app_db.config["SESSION_SQLALCHEMY_TABLE"] = "flask_dance_oauth"

    app_db.config.from_object(__name__)
    #sess = Session(app_db)
    #sess.init_app(app_db)
    dbsl.init_app(app_db)
    app_db.app_context().push()
    return app_db

We really don't know how to fix this, can anyone help?

Emir Sürmen
  • 884
  • 3
  • 14
  • 33
  • Are you using Flask-login to identify users? Or something else? – rfkortekaas Mar 21 '21 at 19:47
  • No, we are not using flask-login anywhere on the code – Emir Sürmen Mar 22 '21 at 11:00
  • So how are you identifying the users? Is there a reference to a user in the request? – rfkortekaas Mar 22 '21 at 11:01
  • Yes, there is a discord endpoint for user info https://imgur.com/aSm60ih.png – Emir Sürmen Mar 22 '21 at 11:05
  • The [`SQLAlchemyStorage`](https://flask-dance.readthedocs.io/en/latest/api.html#flask_dance.consumer.storage.sqla.SQLAlchemyStorage) supports: `user – If you want OAuth tokens to be associated with individual users in your application, this is a reference to the user that you want to use for the current request. It can be an actual User object, a function that returns a User object, or a proxy to the User object. If you’re using Flask-Login, this is current_user.` – rfkortekaas Mar 22 '21 at 12:24
  • Thank you so much, I'll look into it. – Emir Sürmen Mar 22 '21 at 13:31

0 Answers0