Skip to content

Commit

Permalink
Merge branch 'main' into python-sdk-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarbugli authored Aug 2, 2023
2 parents 38f2632 + 1e1ab57 commit e80d4c8
Show file tree
Hide file tree
Showing 19 changed files with 4,268 additions and 1,174 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += -j$(NPROCS)

CURRENT_VERSION_MAJOR = 1
CURRENT_VERSION_MINOR = 7
CURRENT_VERSION_BUG = 1
CURRENT_VERSION_MINOR = 9
CURRENT_VERSION_BUG = 0

GIT_DESCRIBE := $(shell git describe)
GITHUB_HEAD_REF ?= $(shell git branch --show-current)
Expand Down
102 changes: 102 additions & 0 deletions docusaurus/video/docusaurus/docs/api/basics/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,119 @@ slug: /authentication
title: Users & Tokens
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

## Creating users

// TODO API endpoint

## Updating users

// TODO API endpoint

## User tokens

<Tabs groupId="examples">
<TabItem value="js" label="JavaScript">

```js
const userId = 'john';
// exp and iat are optional
// the token will be valid for 1hour
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
const iat = Math.round(new Date().getTime() / 1000);
client.createToken(userId, exp, iat);
```

</TabItem>
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
```

</TabItem>
<TabItem value="go" label="Golang">

```go
func main() {
apiKey := os.Getenv("API_KEY")
apiSecret := os.Getenv("API_SECRET")
userID := os.Getenv("USER_ID")

if apiKey == "" || apiSecret == "" || userID == "" {
panic("API_KEY, API_SECRET and USER_ID env variables must be set")
}

tokenProvider := videosdk.UserToken(apiSecret, userID, 24*time.Hour)
sdk := videosdk.New(apiKey, tokenProvider)

token, err := tokenProvider(sdk.APIKey())
if err != nil {
panic(err)
}

fmt.Println("token ->", token)
}
```

</TabItem>
</Tabs>

## Call tokens

<Tabs groupId="examples">
<TabItem value="js" label="JavaScript">

```js
const userId = 'john';
// exp and iat are optional
// the token will be valid for 1hour
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
const iat = Math.round(new Date().getTime() / 1000);

const call_cids = ['default:call1', 'livestream:call2'];

client.createToken(userId, exp, iat, call_cids);
```

</TabItem>
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
```

</TabItem>
<TabItem value="go" label="Golang">

```go
func main() {
apiKey := os.Getenv("API_KEY")
apiSecret := os.Getenv("API_SECRET")
userID := os.Getenv("USER_ID")

if apiKey == "" || apiSecret == "" || userID == "" {
panic("API_KEY, API_SECRET and USER_ID env variables must be set")
}

tokenProvider := videosdk.UserToken(apiSecret, userID, 24*time.Hour)
sdk := videosdk.New(apiKey, tokenProvider)

token, err := tokenProvider(sdk.APIKey())
if err != nil {
panic(err)
}

fmt.Println("token ->", token)
}
```

</TabItem>
</Tabs>

## Token expiration and token providers

Expand Down
Loading

0 comments on commit e80d4c8

Please sign in to comment.