Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Livefyre/py-livefyre-client
base: e4e3fd0869
...
head fork: Livefyre/py-livefyre-client
compare: 2c48da5867
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 15 additions and 41 deletions.
  1. +9 −39 livefyre/client/token.py
  2. +6 −2 setup.py
View
48 livefyre/client/token.py
@@ -1,14 +1,12 @@
-import hmac
-import hashlib
-from base64 import b64encode, b64decode
-from datetime import datetime
-import time
+import jwt, time
class LFAuthToken(object):
"""Class to create tokens for auth with Livefyre services."""
def __init__(self, user, domain, key, duration=86400):
- self.data = self.populate_data(['auth', domain, user], duration)
- self.key = b64decode(key)
+ self.domain = domain
+ self.duration = duration
+ self.key = key
+ self.user = user
def __str__(self):
"""Return the generated token string."""
@@ -17,35 +15,7 @@ def __str__(self):
@property
def token(self):
"""Create a signed token from inputs."""
- clientkey = bytearray(hmac.new(self.key, b"Client Key", hashlib.sha1).digest())
-
- # python 2.7 is pretty cool with bytearrays
- try:
- clientkey_sha1 = bytearray(hashlib.sha1(clientkey).digest())
- temp = bytearray(hmac.new(clientkey_sha1, self.data, hashlib.sha1).digest())
- sig = bytearray(x ^ y for x, y in zip(bytearray(temp), bytearray(clientkey)))
- ubase64sig = unicode(b64encode(sig))
-
- # python2.6 isn't. fail back to python2.6-style string semantics
- except TypeError, e:
- clientkey_sha1 = bytearray(hashlib.sha1(str(clientkey)).digest())
- temp = bytearray(hmac.new(str(clientkey_sha1), self.data, hashlib.sha1).digest())
- sig = bytearray(x ^ y for x, y in zip(bytearray(temp), bytearray(clientkey)))
- ubase64sig = unicode(b64encode(str(sig)))
-
- return b64encode(",".join([self.data, ubase64sig]))
-
- @classmethod
- def populate_data(cls, arg_list, duration=86400, now=None):
- """Create the right data input for Livefyre authorization."""
- if isinstance(now, datetime):
- now = now.utcnow().isoformat()
- tstamp = now if now else datetime.now().utcnow().isoformat()
-
- args = map(str, arg_list) #convert args to strings
- if filter(lambda x: (',' in x), arg_list):
- raise ValueError('Args can not contain comma (",") chars')
- values = ["lftoken", tstamp, duration] + arg_list
- data = ",".join((str(x) for x in values))
- return unicode(data)
-
+ token = dict(expires=self.duration + time.time(),
+ user_id=self.user,
+ domain=self.domain)
+ return jwt.encode(token, self.key)
View
8 setup.py
@@ -6,7 +6,7 @@ def read(fname):
setup(
name = "livefyre.client",
- version = "0.1.1",
+ version = "0.2",
author = "Nino Walker",
author_email = "support@livefyre.com",
description = ("Livefyre API python client."),
@@ -14,7 +14,11 @@ def read(fname):
keywords = "documentation client",
url = "http://github.com/Livefyre/py-livefyre-client",
packages=['livefyre.client', 'livefyre'],
- install_requires = ['httplib2>=0.6.0', 'python-rest-client>=0.3'],
+ install_requires = [
+ 'httplib2>=0.6.0',
+ 'python-rest-client>=0.3',
+ 'PyJWT>=0.1.4'
+ ],
setup_requires=['nose>=0.11'],
test_suite = "nose.collector",
long_description=read('README.rst'),

No commit comments for this range

Something went wrong with that request. Please try again.