G
G
GDApsy2014-03-04 19:30:34
Flask
GDApsy, 2014-03-04 19:30:34

Ulogin: what causes 'invalid token' error?

The code of the Ulogin panel itself without changes was taken from the constructor and embedded into the page without changes:

<script src="//ulogin.ru/js/ulogin.js"></script>
<div id="uLogin"
 data-ulogin="display=panel;fields=first_name,last_name;providers=vkontakte,facebook,twitter,livejournal,google,openid;hidden=other;redirect_uri=http%3A%2F%2F127.0.0.1%3A5000%2Fauth%2Fsocauth"></div>


In the handler, I receive the user token, and also take the value of the
HTTP_HOST variable and pass them to the object that works with ulogin:
if request.method == 'POST':
     server = request.environ['HTTP_HOST']
     token = request.form['token']
     ulmanager = ulogin.UloginManager(token,server)


In the object, the request for data is carried out:

self.token=token 
self.server = server
url = 'http://ulogin.ru/token.php'
data = urllib.urlencode({'token': self.token, 'host': self.server})
self.ulogin = urllib2.Request(url,data)
self.ulogin = urllib2.urlopen(self.ulogin)
self.ulogin = self.ulogin.read()


The server responds with:
{u'error': u'invalid token'}

The code that is given as an example in the help:

$s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
                    $user = json_decode($s, true);
                    //$user['network'] - соц. сеть, через которую авторизовался пользователь
                    //$user['identity'] - уникальная строка определяющая конкретного пользователя соц. сети
                    //$user['first_name'] - имя пользователя
                    //$user['last_name'] - фамилия пользователя

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GDApsy, 2014-03-05
@GDApsy

The source of the problem was that the value of the token and the server must be passed as the GET method, and in the meantime self.ulogin = urllib2.Request(url,data) assumes that a POST request will be generated, and therefore the data stored in the date variable must be added to the url manually , like so:
data = urllib.urlencode({'token': self.token, 'host': self.server})
ulogin = urllib2.urlopen(url+'?'+data)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question