コード例 #1
0
ファイル: auth_views.py プロジェクト: gmist/3dhero.ru
def login_yandex():
    params = dict(yandex.request_token_params)
    params["client_id"] = yandex.consumer_key
    params["response_type"] = "code"
    params["state"] = util.get_next_url()
    flask.session[yandex.name + "_oauthredir"] = flask.url_for("auth.yandex_authorized")
    url = add_query(yandex.expand_url(yandex.authorize_url), params)
    return flask.redirect(url)
コード例 #2
0
ファイル: auth_views.py プロジェクト: minimedj/3dhero.ru
def login_yandex():
  params = dict(yandex.request_token_params)
  params['client_id'] = yandex.consumer_key
  params['response_type'] = 'code'
  params['state'] = util.get_next_url()
  flask.session[yandex.name + '_oauthredir'] = flask.url_for('auth.yandex_authorized')
  url = add_query(yandex.expand_url(yandex.authorize_url), params)
  return flask.redirect(url)
コード例 #3
0
ファイル: auth_views.py プロジェクト: minimedj/3dhero.ru
def yandex_authorized():
  user_db = None
  state = flask.request.args.get('state')
  try:
      remote_args = {
            'code':             flask.request.args.get('code'),
            'client_id':        yandex.consumer_key,
            'client_secret':    yandex.consumer_secret,
            'grant_type': 'authorization_code'
        }
      remote_args.update(yandex.access_token_params)
      if yandex.access_token_method == 'POST':
        resp, content = yandex._client.request(yandex.expand_url(yandex.access_token_url),
                                                 yandex.access_token_method,
                                                 url_encode(remote_args))
      elif yandex.access_token_method == 'GET':
        url = add_query(yandex.expand_url(yandex.access_token_url), remote_args)
        resp, content = yandex._client.request(url, yandex.access_token_method)
      else:
        raise OAuthException('Unsupported access_token_method: ' +
                                 yandex.access_token_method)
      data = parse_response(resp, content)
      if not yandex.status_okay(resp):
        raise OAuthException('Invalid response from ' + yandex.name,
                                 type='invalid_response', data=data)

      if resp is None:
        return 'Access denied: reason=%s error=%s' % (
          flask.request.args['error_reason'],
          flask.request.args['error_description']
        )
      flask.session['oauth_token'] = (data['access_token'], '')
      me = yandex.get('/info')
      user_db = retrieve_user_from_yandex(me.data)
  except:
    pass
  redirect_url = login_user_db(user_db)
  if state:
      return flask.redirect(state)
  return redirect_url
コード例 #4
0
ファイル: auth_views.py プロジェクト: gmist/3dhero.ru
def yandex_authorized():
    user_db = None
    state = flask.request.args.get("state")
    try:
        remote_args = {
            "code": flask.request.args.get("code"),
            "client_id": yandex.consumer_key,
            "client_secret": yandex.consumer_secret,
            "grant_type": "authorization_code",
        }
        remote_args.update(yandex.access_token_params)
        if yandex.access_token_method == "POST":
            resp, content = yandex._client.request(
                yandex.expand_url(yandex.access_token_url), yandex.access_token_method, url_encode(remote_args)
            )
        elif yandex.access_token_method == "GET":
            url = add_query(yandex.expand_url(yandex.access_token_url), remote_args)
            resp, content = yandex._client.request(url, yandex.access_token_method)
        else:
            raise OAuthException("Unsupported access_token_method: " + yandex.access_token_method)
        data = parse_response(resp, content)
        if not yandex.status_okay(resp):
            raise OAuthException("Invalid response from " + yandex.name, type="invalid_response", data=data)

        if resp is None:
            return "Access denied: reason=%s error=%s" % (
                flask.request.args["error_reason"],
                flask.request.args["error_description"],
            )
        flask.session["oauth_token"] = (data["access_token"], "")
        me = yandex.get("/info")
        user_db = retrieve_user_from_yandex(me.data)
    except:
        pass
    redirect_url = login_user_db(user_db)
    if state:
        return flask.redirect(state)
    return redirect_url