Skip to content

Commit 3753092

Browse files
committed
Return token as dictionary
1 parent 1bb5a15 commit 3753092

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pusher_push_notifications/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def generate_token(self, user_id):
349349
user_id (string): user id for which the token will be valid
350350
351351
Returns:
352-
auth token for the requested user id (string)
352+
Beams token wrapped in dictionary for json serialization (dict)
353353
354354
Raises:
355355
TypeError: if user_id is not a string
@@ -367,7 +367,7 @@ def generate_token(self, user_id):
367367
expiry_datetime = now + AUTH_TOKEN_DURATION
368368
expiry_timestamp = int(time.mktime(expiry_datetime.timetuple()))
369369

370-
return jwt.encode(
370+
token = jwt.encode(
371371
{
372372
'iss': issuer,
373373
'sub': user_id,
@@ -377,6 +377,10 @@ def generate_token(self, user_id):
377377
algorithm='HS256',
378378
).decode('utf-8')
379379

380+
return {
381+
'token': token,
382+
}
383+
380384
def delete_user(self, user_id):
381385
"""Remove the user with the given ID (and all of their devices) from
382386
the Pusher Beams database. The user will no longer receive any

tests/test_users.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ def test_generate_token_should_return_token(self):
2525
'SECRET_KEY'
2626
)
2727

28-
token_string = pn_client.generate_token(user_id)
28+
token_object = pn_client.generate_token(user_id)
29+
self.assertIsInstance(token_object, dict)
2930

31+
token_string = token_object.get('token')
3032
self.assertIsInstance(token_string, six.string_types)
33+
3134
self.assertTrue(len(token_string) > 0)
3235

3336
decoded_token = jwt.decode(

0 commit comments

Comments
 (0)