Skip to content

Commit

Permalink
Add payload extender into generate_access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins committed Dec 29, 2019
1 parent b5d4ff3 commit 5ba6a88
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sanic_jwt/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,21 @@ def extract_user_id(self, request):
user_id_attribute = self.config.user_id()
return payload.get(user_id_attribute, None)

async def generate_access_token(self, user, custom_claims=None):
async def generate_access_token(
self, user, extend_payload=None, custom_claims=None
):
"""
Generate an access token for a given user.
"""
payload = await self._get_payload(user, inline_claims=custom_claims)
secret = self._get_secret(True)
algorithm = self._get_algorithm()

if extend_payload:
payload = await utils.call(
extend_payload, payload=payload, user=user
)

return jwt.encode(payload, secret, algorithm=algorithm).decode("utf-8")

async def generate_refresh_token(self, request, user):
Expand Down

0 comments on commit 5ba6a88

Please sign in to comment.