Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ python:
- 3.4
- 3.5
- 3.6
- 3.7

matrix:
fast_finish: true
include:
- python: 3.7
dist: xenial
sudo: true

cache: pip

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Change history
================

======
2.12.0
======
:release-date: 2018-10-08
:by: Peter van Kampen

Add user-session-token support

======
2.11.0
======
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
if sys.version_info < (2, 7, 0):
install_requires.append('pyOpenSSL<18.0.0')
install_requires.append('pyjwt>=1.3.0,<1.6.0')
install_requires.append('pycparser<2.19')
else:
install_requires.append('pyjwt>=1.3.0,<1.7.0')

Expand Down
2 changes: 1 addition & 1 deletion stream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__copyright__ = 'Copyright 2014, Stream.io, Inc'
__credits__ = ['Thierry Schellenbach, mellowmorning.com, @tschellenbach']
__license__ = 'BSD-3-Clause'
__version__ = '2.11.0'
__version__ = '2.12.0'
__maintainer__ = 'Thierry Schellenbach'
__email__ = 'support@getstream.io'
__status__ = 'Production'
Expand Down
11 changes: 11 additions & 0 deletions stream/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ def _make_signed_request(self, method_name, relative_url, params=None, data=None
response.url, headers, data)
return self._parse_response(response)

def create_user_session_token(self, user_id, **extra_data):
'''Setup the payload for the given user_id with optional
extra data (key, value pairs) and encode it using jwt
'''
payload = {
'user_id': user_id,
}
for k, v in extra_data.items():
payload[k] = v
return jwt.encode(payload, self.api_secret, algorithm='HS256').decode("utf-8")

def create_jwt_token(self, resource, action, feed_id=None, user_id=None):
'''
Setup the payload for the given resource, action, feed or user
Expand Down
10 changes: 10 additions & 0 deletions stream/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ def test_token_retrieval(self):
self.user1.token
self.user1.get_readonly_token()

def test_user_session_token(self):
client = stream.connect(self.c.api_key, self.c.api_secret)
token = client.create_user_session_token("user")
payload = jwt.decode(token, self.c.api_secret)
self.assertEqual(payload["user_id"], "user")
token = client.create_user_session_token("user", client="python", testing=True)
payload = jwt.decode(token, self.c.api_secret)
self.assertEqual(payload["client"], "python")
self.assertEqual(payload["testing"], True)

def test_add_activity(self):
feed = getfeed("user", "py1")
activity_data = {"actor": 1, "verb": "tweet", "object": 1}
Expand Down