Client & Authentication
Client & Auth
Before joining a call, it is necessary to set up the video client. Here's a basic example:
let streamVideo = StreamVideo(
apiKey: apiKey,
user: user,
token: token,
tokenProvider: { _ in }
)
- The API Key can be found in your dashboard.
- The user can be either authenticated, anonymous or guest.
- Note: You can store custom data on the user object, if required.
Typically, you'll want to initialize the client in your app's AppDelegate or SceneDelegate or in a dependency injection module.
Generating a token
Tokens need to be generated server side. You can use our server side SDKs to quickly add support for this. Typically you integrate this into the part of your codebase where you login or register users. The tokens provide a way to authenticate a user or give access to a specific set of calls.
Here's a valid user and token to help you get started on the client side, before integrating with your backend API.
Here are credentials to try out the app with:
Property | Value |
---|---|
API Key | Waiting for an API key ... |
Token | Token is generated ... |
User ID | Loading ... |
Call ID | Creating random call ID ... |
Different types of users
Authenticated users are users that have an account on your app. Guest users are temporary user accounts. You can use it to temporarily give someone a name and image when joining a call. Anonymous users are users that are not authenticated. It's common to use this for watching a livestream or similar where you aren't authenticated.
This example shows the client setup for a guest user:
let streamVideo = StreamVideo(
apiKey: apiKey,
user: .guest("guest"),
token: token,
tokenProvider: { _ in }
)
And here's an example for an anonymous user
let streamVideo = StreamVideo(
apiKey: apiKey,
user: .anonymous,
token: token,
tokenProvider: { _ in }
)
Client options
Here's a more complete example of the client options:
let streamVideo = StreamVideo(
apiKey: apiKey,
user: user,
token: token,
videoConfig: VideoConfig(),
pushNotificationsConfig: .default,
tokenProvider: { _ in }
)
The full list of supported options is:
Option | Description | Default |
---|---|---|
apiKey | The API key to use. Found in the dashboard | - |
user | The user object. You can store custom data on the user. | - |
token | The JWT token to use for authentication. | - |
videoConfig | A VideoConfig instance representing the current video config. | VideoConfig() |
pushNotificationsConfig | Config for push notifications. | .default |
tokenProvider | A function to call if the token is expired or invalid. | - |