I'm using Flask-Dance to use Google to login to my application. I am also using SQLAlchemy and Flask-Login.
Everything regarding the Google login is working perfectly but it is supposed to save the token data in a table created by SQLAlchemy (flask_dance_oauth) but it isn't. Every time I login, it doesn't save the token data in the table, even though I specified it.
from app import db
from flask_dance.contrib.google import make_google_blueprint
from flask_dance.consumer.storage.sqla import SQLAlchemyStorage
from flask_login import current_user
from Tables import OAuth
blueprint = make_google_blueprint(
client_id="clientid",
client_secret="secret",
scope=['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email',
'openid'],
storage=SQLAlchemyStorage(OAuth, db.session, user=current_user))
And my SQLAlchemy class:
from app import db
from datetime import *
from flask_dance.consumer.storage.sqla import OAuthConsumerMixin
from flask_login import UserMixin
class Users(UserMixin, db.Model):
__bind_key__ = 'users'
id = db.Column(db.Integer, primary_key=True)
uuid = db.Column(db.String(50), index=True, unique=True)
email = db.Column(db.String(100), unique=True)
fname = db.Column(db.String(20))
lname = db.Column(db.String(20))
authenticated = db.Column(db.Boolean, default=True)
class OAuth(OAuthConsumerMixin, db.Model):
__bind_key__ = 'users'
user_id = db.Column(db.String(50), db.ForeignKey(Users.uuid))
user = db.relationship(Users)
The curious part is that I did this exact same code in another project and it worked perfectly. But in this one it won't. Could it be because of the way the User table is built? The one here has first name and last name, but the User table in the other project I made only has the UUID and the email. Any help will be appreciated.