Exemple #1
0
def auth_token():
    ac = 'Access-Control-'
    headers = {}

    if 'origin' in request.headers:
        headers[ac + 'Allow-Origin'] = request.headers['origin']
        headers[ac + 'Allow-Credentials'] = 'true'
        headers[ac +
                'Expose-Headers'] = 'Location, Content-Type, Content-Length'

        if request.method == 'OPTIONS':
            headers[
                ac +
                'Allow-Headers'] = 'X-Requested-With, Content-Type, Content-Length'
            headers[ac + 'Allow-Methods'] = 'GET, OPTIONS'
            headers[ac + 'Max-Age'] = '86400'

    if g.user:
        c = Consumer.fetch('annotateit')
        payload = {
            'consumerKey': c.key,
            'userId': g.user.username,
            'ttl': c.ttl
        }
        if g.user.is_admin:
            payload['admin'] = True
        token = auth.encode_token(payload, c.secret)
        return Response(token, headers=headers, mimetype='text/plain')
    else:
        return Response('Please go to {0} to log in!'.format(request.host_url),
                        status=401,
                        headers=headers,
                        mimetype='text/plain')
Exemple #2
0
def auth_token():
    ac = 'Access-Control-'
    headers = {}

    if 'origin' in request.headers:
        headers[ac + 'Allow-Origin']      = request.headers['origin']
        headers[ac + 'Allow-Credentials'] = 'true'
        headers[ac + 'Expose-Headers']    = 'Location, Content-Type, Content-Length'

        if request.method == 'OPTIONS':
            headers[ac + 'Allow-Headers'] = 'X-Requested-With, Content-Type, Content-Length'
            headers[ac + 'Allow-Methods'] = 'GET, OPTIONS'
            headers[ac + 'Max-Age']       = '86400'

    if g.user:
        c = Consumer.fetch('annotateit')
        payload = {'consumerKey': c.key, 'userId': g.user.username, 'ttl': c.ttl}
        if g.user.is_admin:
            payload['admin'] = True
        token = auth.encode_token(payload, c.secret)
        return Response(token, headers=headers, mimetype='text/plain')
    else:
        return Response('Please go to {0} to log in!'.format(request.host_url), status=401, headers=headers, mimetype='text/plain')
 def test_default_ttl(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.ttl, 86400)
 def test_secret(self):
     c = Consumer.fetch('foo')
     assert c.secret, 'Consumer secret should be set!'
 def test_key(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.key, 'foo')
Exemple #6
0
 def consumer(self):
     if not hasattr(self, '_consumer'):
         self._consumer = Consumer.fetch('annotateit')
     return self._consumer
Exemple #7
0
 def consumer(self):
     if not hasattr(self, '_consumer'):
         self._consumer = Consumer.fetch('annotateit') # Allen change to admin
     return self._consumer
Exemple #8
0
 def test_default_ttl(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.ttl, 86400)
Exemple #9
0
 def test_secret(self):
     c = Consumer.fetch('foo')
     assert c.secret, 'Consumer secret should be set!'
Exemple #10
0
 def test_key(self):
     c = Consumer.fetch('foo')
     h.assert_equal(c.key, 'foo')