I am writing a Sina Weibo client through oauth2 to add authentication to the current user who has already connected to my own site account, since OAuth2 uses the redirect-callback mechanism, it seems that after this procedure and in the callback view handler, flask.session - This is a completely new facility. Thus, I lost the current user login status.
but in the same browser (e.g. Firefox) to add a new tab and visit the homepage of my site (www.funfunsay.com), the session object still exists!
So, in one instance of the browser there are two flash drives.
I wrote a very simple module, it goes well with Sina weibo, except that I lost the old session.
from flask import (Flask, render_template, current_app, request,
flash, url_for, redirect, session, g, abort)
__all__ = ['create_app']
app = Flask(__name__)
app.config['DEBUG'] = True
app.secret_key = 'secret key'
@app.before_request
def before_request():
print "before request:", session
@app.after_request
def after(response):
print "after request:", session
return response
@app.route('/')
def hello_world():
print "request:", request
login_uri = 'https://api.weibo.com/oauth2/authorize?redirect_uri=http%3A//funfunsay.com/connect/sina/callback&response_type=code&client_id=3921006605&display=default'
session['testinfo'] = 'abc'
return redirect(login_uri)
@app.route("/connect/sina/callback")
def connect_sina_callback():
print "connect_sina_callback: ", session
return 'Callback success!'
if __name__ == '__main__':
app.run('0.0.0.0', 80)
PS: "127.0.0.1 www.funfunsay.com" .