Update token using Google API via Flask-Dance

I find it very difficult to implement Google OAuth with Flask-Dance. Here is the deal. To do everything, I need to install offline=True and reprompt_consent=Truewhen creating a Google plan:

google_bp = make_google_blueprint(
    client_id="trololo",
    client_secret="ololo",
    offline=True,
    reprompt_consent=True,
    scope=["email"],
    redirect_url="/callback/google"
)

However reprompt_consent=True, naturally, the user makes the reprompt application for offline access every time the user logs on.

Any other combination of these 2 parameters results in a lack of refresh_tokenfor Oauth2lib.

I do not need offline access as such, but as I understand it, this is the only way to avoid this error. So, is there another way to log in using Google using Flask-Dance and pass this one on refresh_token?

+4
1

, - google Backend, - OAuth. , .

from flask_sqlalchemy import SQLAlchemy
from flask_login import current_user
from flask_dance.consumer.backend.sqla import OAuthConsumerMixin, SQLAlchemyBackend

db = SQLAlchemy()

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    # ... other columns as needed

class OAuth(OAuthConsumerMixin, db.Model):
    user_id = db.Column(db.Integer, db.ForeignKey(User.id))
    user = db.relationship(User)

blueprint.backend = SQLAlchemyBackend(OAuth, db.session, user=current_user)

SQL db .

+1

Source: https://habr.com/ru/post/1667490/


All Articles