Overview
When using the Stream Mobile SDKs, two authentication layers exist:- Embed View Token Authentication: controls access to the video
- CDN Token Authentication: protects delivery from Bunny CDN and is handled automatically by the SDK
Embed View Token Authentication
Purpose
- Authorizes a viewer to play a specific video
- Enforced at the Stream API level
- Required for private or restricted videos
Mobile SDK Responsibility
- The customer backend generates the token
- The mobile app requests the token and passes it to the SDK player element
- The SDK uses the token for playback; CDN token signing happens automatically
Supported Authentication Methods
| Method | Mobile SDK |
|---|---|
| Embed View Token Authentication | Supported via customer backend |
| CDN Token Authentication | Automatic |
| Client-side token signing | Not supported |
Backend Requirements
The backend (or Edge Script) must:- Securely store the Video Library API Key as it serves as a secret that must not be stored in the mobile app
- Authenticate the mobile app user with custom business logic
- Generate embed view token by following the token authentication signing procedure (token security key is your Video Library API Key)
-
Return a
tokenandexpiresvalues in response:
Edge Script Example
Below is an example Edge Script that generates embed view tokens. StoreVIDEO_LIBRARY_API_KEY as an Edge Script Secret.
Android SDK Usage
ThePlayVideo call supports token parameters:
- Request embed token from backend
- Receive
{ token, expires } - Pass values to
PlayVideo
iOS SDK Usage
TheBunnyStreamPlayer initializer supports token parameters:
- Request embed token from backend
- Receive
{ token, expires } - Initialize player with token data
Important Notes
- The Video Library API Key must never be included in mobile apps
- Embed View Token Authentication is required if you don’t want to publicly expose your videos
- CDN Token Authentication is applied to CDN URLs automatically if turned on in the video library