diff --git a/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx b/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx index 1466d773..c24f6192 100644 --- a/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx +++ b/docusaurus/video/docusaurus/docs/api/basics/authentication.mdx @@ -220,15 +220,26 @@ client.createToken(userId, exp); ```py +# in this example we use Django +# but you can use any framework you like import time +from django.contrib.auth.decorators import login_required +from django.http import JsonResponse -# user ID -user_id = 'john' +# The user token endpoint is protected with the login_required decorator. +@login_required +def create_user_token(request): + # The 'user_id' is retrieved from the request's user instance. + user_id = request.user.id -# the token will be valid for 1 hour -exp = int(time.time()) + 60 * 60 + # the token will be valid for 1 hour + exp = int(time.time()) + 60 * 60 + # Here client is Stream client and it's called with the 'user_id' and the expiration time. + token = client.create_token(user_id, expiration = exp) + + # The token is then returned in the response. + return JsonResponse({'token': token}) -client.create_token(user_id = user_id, expiration = exp) ```