requests_oauthlib oauth方法

时间:2015-07-08 08:24:13

标签: python oauth flask

我正在使用requests_oauthlib OAuth2Session从Github API获取oauth。 当我访问令牌授权URL和请求的状态并将其保存在会话中时,它实际上并没有执行该语句。在回调URL处理期间,它显示如下错误:

  

' oauth_state'未定义

我的代码是:

@app.route("/")
def demo():
    """Step 1: User Authorization.

    Redirect the user/resource owner to the OAuth provider (i.e. Github)
    using an URL with a few key OAuth parameters.
    """
    github = OAuth2Session(client_id)
    authorization = list(github.authorization_url(authorization_base_url))

    # State is used to prevent CSRF, keep this for later.
    global state
    state = authorization[1]
    return redirect(authorization[0])

@app.route('/support',methods=["GET"])
def support():
    global state
    github = OAuth2Session(client_id,state=state)
    #token = github.fetch_token(token_url,client_secret=client_secret, authorization_response=request.url)

    #session['oauth_token'] = token

    return "Request url is %s AND STATE stored in session is %s" % (request.url, state)

请在检索回复网址处理的oauth_state时帮我解决此错误,以便我的应用正常运行。

0 个答案:

没有答案