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
8 changes: 6 additions & 2 deletions pusher_push_notifications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def generate_token(self, user_id):
user_id (string): user id for which the token will be valid

Returns:
auth token for the requested user id (string)
Beams token wrapped in dictionary for json serialization (dict)

Raises:
TypeError: if user_id is not a string
Expand All @@ -367,7 +367,7 @@ def generate_token(self, user_id):
expiry_datetime = now + AUTH_TOKEN_DURATION
expiry_timestamp = int(time.mktime(expiry_datetime.timetuple()))

return jwt.encode(
token = jwt.encode(
{
'iss': issuer,
'sub': user_id,
Expand All @@ -377,6 +377,10 @@ def generate_token(self, user_id):
algorithm='HS256',
).decode('utf-8')

return {
'token': token,
}

def delete_user(self, user_id):
"""Remove the user with the given ID (and all of their devices) from
the Pusher Beams database. The user will no longer receive any
Expand Down
5 changes: 4 additions & 1 deletion tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ def test_generate_token_should_return_token(self):
'SECRET_KEY'
)

token_string = pn_client.generate_token(user_id)
token_object = pn_client.generate_token(user_id)
self.assertIsInstance(token_object, dict)

token_string = token_object.get('token')
self.assertIsInstance(token_string, six.string_types)

self.assertTrue(len(token_string) > 0)

decoded_token = jwt.decode(
Expand Down