Skip to content

Commit

Permalink
django snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaarbonel committed Nov 10, 2023
1 parent 14312c2 commit 5745d40
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions docusaurus/video/docusaurus/docs/api/basics/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,26 @@ client.createToken(userId, exp);
<TabItem value="py" label="Python">

```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)
```

</TabItem>
Expand Down

0 comments on commit 5745d40

Please sign in to comment.