Beispiel #1
0
def odnoklassniki_authorized(resp):
  if resp is None:
    return 'Access denied: reason=%s error=%s' % (
      flask.request.args['error_reason'],
      flask.request.args['error_description']
    )
  access_token = resp['access_token']
  flask.session['oauth_token'] = (access_token, '')
  try:
      data={
      'method':'users.getCurrentUser',
      'application_key':odnoklassniki.consumer_public,
      'access_token':access_token,
      }
      data['sig']=odnoklassniki_oauth_sig(data, client_secret=odnoklassniki.consumer_secret)
      params = urlencode(data)
      url = odnoklassniki.base_url + 'fb.do'
      request = Request(url, params)
      odnoklassniki_resp = json.loads(urlopen(request).read())
      user_db = retrieve_user_from_odnoklassniki(odnoklassniki_resp)
  except:
      flask.flash(
        u'Упс, что-то пошло не так, попробуйте зайти позже.',
        category='danger'
      )
      return flask.redirect(flask.url_for('auth.login', next=util.get_next_url()))
  return login_user_db(user_db)
Beispiel #2
0
def mailru_authorized(resp):
  if resp is None:
    return 'Access denied: reason=%s error=%s' % (
      flask.request.args['error_reason'],
      flask.request.args['error_description']
    )
  access_token = resp['access_token']
  flask.session['oauth_token'] = (access_token, '')
  try:
    data={
    'method':'users.getInfo',
    'app_id':mailru.consumer_key,
    'session_key':access_token,
    'secure':'1'
    }
    data['sig']=mailru_sig(data)
    params = urlencode(data)
    url = mailru.base_url + 'platform/api'
    request = Request(url, params)
    mailru_resp = json.loads(urlopen(request).read())
    user_db = retrieve_user_from_mailru(mailru_resp[0])
  except:
    flask.flash(
      u'Упс, что-то пошло не так, попробуйте зайти позже.',
      category='danger'
    )
    return flask.redirect(flask.url_for('auth.login', next=util.get_next_url()))
  return login_user_db(user_db)
Beispiel #3
0
def twitter_oauth_authorized(resp):
    if resp is None:
        flask.flash(u"You denied the request to sign in.")
        return flask.redirect(util.get_next_url())

    flask.session["oauth_token"] = (resp["oauth_token"], resp["oauth_token_secret"])
    user_db = retrieve_user_from_twitter(resp)
    return login_user_db(user_db)
Beispiel #4
0
def google_authorized():
    google_user = users.get_current_user()
    if google_user is None:
        flask.flash(u"You denied the request to sign in.")
        return flask.redirect(util.get_next_url())

    user_db = retrieve_user_from_google(google_user)
    return login_user_db(user_db)
Beispiel #5
0
def google_authorized():
  google_user = users.get_current_user()
  if google_user is None:
    flask.flash(u'You denied the request to sign in.')
    return flask.redirect(util.get_next_url())

  user_db = retrieve_user_from_google(google_user)
  return login_user_db(user_db)
Beispiel #6
0
def facebook_authorized(resp):
    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"] = (resp["access_token"], "")
    me = facebook.get("/me")
    user_db = retrieve_user_from_facebook(me.data)
    return login_user_db(user_db)
Beispiel #7
0
def facebook_authorized(resp):
  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'] = (resp['access_token'], '')
  me = facebook.get('/me')
  user_db = retrieve_user_from_facebook(me.data)
  return login_user_db(user_db)
Beispiel #8
0
def vk_authorized(resp):
    if resp is None:
        return "Access denied: reason=%s error=%s" % (
            flask.request.args["error_reason"],
            flask.request.args["error_description"],
        )
    access_token = resp["access_token"]
    flask.session["oauth_token"] = (access_token, "")
    me = vk.get("/method/getUserInfoEx", data={"access_token": access_token})
    user_db = retrieve_user_from_vk(me.data["response"])
    return login_user_db(user_db)
Beispiel #9
0
def twitter_oauth_authorized(resp):
  if resp is None:
    flask.flash(u'You denied the request to sign in.')
    return flask.redirect(util.get_next_url())

  flask.session['oauth_token'] = (
    resp['oauth_token'],
    resp['oauth_token_secret']
  )
  user_db = retrieve_user_from_twitter(resp)
  return login_user_db(user_db)
Beispiel #10
0
def vk_authorized(resp):
  if resp is None:
    return 'Access denied: reason=%s error=%s' % (
      flask.request.args['error_reason'],
      flask.request.args['error_description']
    )
  access_token = resp['access_token']
  flask.session['oauth_token'] = (access_token, '')
  me = vk.get('/method/getUserInfoEx', data={'access_token':access_token})
  user_db = retrieve_user_from_vk(me.data['response'])
  return login_user_db(user_db)
Beispiel #11
0
def mailru_authorized(resp):
    if resp is None:
        return "Access denied: reason=%s error=%s" % (
            flask.request.args["error_reason"],
            flask.request.args["error_description"],
        )
    access_token = resp["access_token"]
    flask.session["oauth_token"] = (access_token, "")
    try:
        data = {"method": "users.getInfo", "app_id": mailru.consumer_key, "session_key": access_token, "secure": "1"}
        data["sig"] = mailru_sig(data)
        params = urlencode(data)
        url = mailru.base_url + "platform/api"
        request = Request(url, params)
        mailru_resp = json.loads(urlopen(request).read())
        user_db = retrieve_user_from_mailru(mailru_resp[0])
    except:
        flask.flash(u"Упс, что-то пошло не так, попробуйте зайти позже.", category="danger")
        return flask.redirect(flask.url_for("auth.login", next=util.get_next_url()))
    return login_user_db(user_db)
Beispiel #12
0
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
Beispiel #13
0
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
Beispiel #14
0
def odnoklassniki_authorized(resp):
    if resp is None:
        return "Access denied: reason=%s error=%s" % (
            flask.request.args["error_reason"],
            flask.request.args["error_description"],
        )
    access_token = resp["access_token"]
    flask.session["oauth_token"] = (access_token, "")
    try:
        data = {
            "method": "users.getCurrentUser",
            "application_key": odnoklassniki.consumer_public,
            "access_token": access_token,
        }
        data["sig"] = odnoklassniki_oauth_sig(data, client_secret=odnoklassniki.consumer_secret)
        params = urlencode(data)
        url = odnoklassniki.base_url + "fb.do"
        request = Request(url, params)
        odnoklassniki_resp = json.loads(urlopen(request).read())
        user_db = retrieve_user_from_odnoklassniki(odnoklassniki_resp)
    except:
        flask.flash(u"Упс, что-то пошло не так, попробуйте зайти позже.", category="danger")
        return flask.redirect(flask.url_for("auth.login", next=util.get_next_url()))
    return login_user_db(user_db)