English 中文(简体)
如何恢复地图集。 宣誓2
原标题:How to resume flask.session object when oath2 callback

I mpaper Sina Weibouser through oauth2 to increase accreditation to currentuser who have beenloged in with my own website s account, since OAuth2 use a redirect-questback mechanism, it trends that after this practice, and in the Callback viewhandler, the flask. 会议完全是一个新目标。 因此,一失去目前用户的标识。

...... 在同一个浏览器(如Landor)中,添加一个新的表格并访问我的网页(www.funfunsay.com),本届会议的物体仍然存在!

因此,有两部地图。 同一浏览器场的会议?

我写了一个非常简单的模块,除我失去旧会议外,它很好地与Sina Weibo有关。

# -*- coding: utf-8 -*-

from flask import (Flask, render_template, current_app, request,
                   flash, url_for, redirect, session, g, abort)


# For import *
__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
    #<1st output>for first visit www.funfunsay.com, the output is: before request: <SecureCookieSession {}>
    #<3rd output>for callback from sina, the output is the same

@app.after_request
def after(response):
    print "after request:", session
    #<2nd output>for first visit www.funfunsay.com, the output is: after request: <SecureCookieSession { testinfo :  abc }*>
    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  #a key-value for test

    return redirect(login_uri)

@app.route("/connect/sina/callback")
def connect_sina_callback():
    print "connect_sina_callback: ", session
    #<4th output>will output: connect_sina_callback:  <SecureCookieSession {}>
    return  Callback success! 

if __name__ ==  __main__ :
    app.run( 0.0.0.0 , 80)

PS:为了测试目的,我在东道方档案中添加“127.0.0.1 www.funfunsay.com”。

问题回答

保持域名的一致性。 如果进入“M-web-site.com”的用户将其转至“www.my-web-site.com”,我的解决办法总是使用“www.my-web-site.com”。 如今,一切都是ok!

弗拉茨克为从不同起源点提出的每一项请求指派了新的会议,即使地址对同一知识产权的解决,从一个不同起点提出的每一项请求都将指定一个不同的会议。 E.g. 浏览器窗口开始在http:// localhost:5000上,将从同一浏览器窗口的表格中分到另一场会议,专门用于127.0.0.1:5000。 ......即使双方决心在同一地点。

这可能令人沮丧,因为一届会议的数据不能在同一浏览器中提供给另一个表格,正如你所期望的那样。 虽然一届会议可能 ha忙地储存你通过网站收集的所有数据,但另一个表格将有一个空码<>session。

在与奥乌特呼吁回合时,我发现这种trick缩最容易,当时我需要确保电网(在你重新发送请求的服务器上界定)与我提出我的要求的现场相匹配。 例如,如果我的奥阿瑟应用程序在Github API开发机网页上将电离灯列为:http:// localhost:5000/questback。 我无法把我的浏览器点到<代码>http://127.0.0.1:5000,因为反馈将在新的一届会议上启动,并有空闲的会议数据。

幸运的是,这样做容易(至少在制定<条码>的地方<><>>>>/代码>时):确保你使用东道国的相同格式对网站进行测试,如你在数据提供者S Outh Application中界定的“URL”的背式(在你界定你在“例如”中的用意时)。 Facebook、Twitter或Github OAuth API小组。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签