示例#1
0
def auth_callback(resp):
    access_token = resp['access_token']
    # Check the access token by fetching user info.
    google_user_info = fetch_google_user_info(access_token)
    if google_user_info:
        email = google_user_info.get("email")
        if email:
            user = UserSessions.load(email)
            if user:
                user.set_authenticated()
                user.set_access_token(access_token)
                # This is flask-login's login method.
                login_user(user)
                return redirect(request.args.get("next") or url_for("root"))
    # Otherwise this user is not known and access is not allowed.
    return redirect(url_for("unauthorized_user"))
示例#2
0
def load_user(userid):
    return UserSessions.load(userid)