Skip to content

Commit 9efa7a9

Browse files
lukasIOMaxHeimbrock
authored andcommitted
chore: introduce DevelopmentTokenSource and deprecate SandboxTokenSource
1 parent e638f6f commit 9efa7a9

6 files changed

Lines changed: 52 additions & 41 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ export LIVEKIT_TOKEN=$(lk token create \
213213
```
214214

215215
Pass `LIVEKIT_URL` and `LIVEKIT_TOKEN` into `Room::connect`, or use the SDK's
216-
token source helpers for endpoint, sandbox, and custom backends. See
216+
token source helpers for endpoint, development token server, and custom backends. See
217217
[docs/authentication.md](docs/authentication.md).
218218

219219
## Features
220220

221221
- Connect to LiveKit rooms (Cloud or self-hosted)
222-
- Dynamic token sourcing (literal, custom, endpoint, sandbox, caching)
222+
- Dynamic token sourcing (literal, custom, endpoint, development token server, caching)
223223
- Receive remote audio/video tracks
224224
- Publish local audio/video tracks
225225
- Data tracks (low-level) and data streams (high-level)

‎docs/authentication.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ them:
8080
```cpp
8181
#include <livekit/token_source.h>
8282
83-
auto source = /* EndpointTokenSource, SandboxTokenSource, CustomTokenSource, etc. */;
83+
auto source = /* EndpointTokenSource, DevelopmentTokenSource, CustomTokenSource, etc. */;
8484
auto credentials = source->fetch(request_options).get();
8585
if (!credentials ||
8686
!room.connect(credentials.value().server_url, credentials.value().participant_token, options)) {
@@ -107,7 +107,7 @@ again only happens when your application invokes it again.
107107
|---|---|---|
108108
| **Literal** | `LiteralTokenSource` | Static URL + JWT, or lazy async provider |
109109
| **Endpoint** | `EndpointTokenSource` | Production: HTTP token server on your backend |
110-
| **Sandbox** | `SandboxTokenSource` | Development: LiveKit Cloud sandbox token server |
110+
| **Development Token Server** | `DevelopmentTokenSource` | Development: LiveKit Cloud development token server (previously: sandbox) |
111111
| **Custom** | `CustomTokenSource` | Your own async credential logic |
112112
| **Caching** | `CachingTokenSource` | Decorator: JWT-aware cache around a configurable source |
113113

@@ -168,12 +168,12 @@ if (!credentials ||
168168
}
169169
```
170170
171-
### Sandbox (development only)
171+
### Development Token Server (development only)
172172
173-
Uses the LiveKit Cloud sandbox token server. Do not use in production.
173+
Uses the LiveKit Cloud development token server. Do not use in production.
174174
175175
```cpp
176-
auto source = livekit::SandboxTokenSource::create("your-sandbox-id");
176+
auto source = livekit::DevelopmentTokenSource::create("your-sandbox-id");
177177
178178
livekit::TokenRequestOptions request;
179179
request.agent_name = "my-agent"; // optional agent dispatch
@@ -187,6 +187,9 @@ if (!credentials ||
187187

188188
See [sandbox token server docs](https://docs.livekit.io/frontends/build/authentication/sandbox-token-server/).
189189

190+
> `SandboxTokenSource` / `SandboxTokenServerOptions` remain as deprecated aliases for
191+
> `DevelopmentTokenSource` / `DevelopmentTokenServerOptions`; prefer the new names.
192+
190193
### Custom
191194

192195
Integrate an existing auth system without adopting the standard endpoint wire

‎include/livekit/token_source.h‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ struct TokenSourceResponse {
5454
std::optional<std::string> room_name;
5555
};
5656

57-
/// @brief Per-call options sent to configurable token sources (endpoint, sandbox, custom).
57+
/// @brief Per-call options sent to configurable token sources (endpoint, development, custom).
5858
///
5959
/// All fields are optional. Unset or empty values are omitted from the token-server
6060
/// request body. The token server embeds the provided values into the returned JWT;
6161
/// @ref Room::connect does not read these options directly after fetch — the room,
6262
/// identity, and grants come from the token.
6363
///
6464
/// @note Which fields are honored depends on the token server. The LiveKit Cloud
65-
/// sandbox token server auto-generates @c room_name, @c participant_identity, and
65+
/// development token server auto-generates @c room_name, @c participant_identity, and
6666
/// related fields when they are omitted. A project token endpoint typically accepts
6767
/// the full set below, including agent dispatch via @c room_config.
6868
struct TokenRequestOptions {
6969
/// Target room name encoded into the token request.
7070
///
7171
/// Set this when you need a stable room across reconnects or when coordinating
7272
/// multiple clients in the same session. If omitted, many token servers (including
73-
/// the sandbox) assign a new room name on each fetch, so repeat connections may
73+
/// the development token server) assign a new room name on each fetch, so repeat connections may
7474
/// land in different rooms.
7575
std::optional<std::string> room_name;
7676

@@ -139,8 +139,8 @@ struct TokenEndpointOptions {
139139
std::chrono::milliseconds timeout = std::chrono::seconds(30);
140140
};
141141

142-
/// @brief Options for @ref SandboxTokenSource.
143-
struct SandboxTokenServerOptions {
142+
/// @brief Options for @ref DevelopmentTokenSource.
143+
struct DevelopmentTokenServerOptions {
144144
/// LiveKit Cloud API base URL (default @c https://cloud-api.livekit.io).
145145
std::string base_url = "https://cloud-api.livekit.io";
146146
};
@@ -283,36 +283,45 @@ class LIVEKIT_API EndpointTokenSource final : public TokenSourceConfigurable {
283283
friend struct EndpointTokenSourceTestAccess;
284284
};
285285

286-
/// @brief Token source that uses LiveKit Cloud's sandbox token server (development only).
286+
/// @brief Token source that uses LiveKit Cloud's development token server (development only).
287287
///
288288
/// Use this for local development and quick testing when you do not yet have your
289289
/// own backend token endpoint. Do not use in production.
290290
///
291291
/// @see https://docs.livekit.io/frontends/build/authentication/sandbox-token-server/
292-
class LIVEKIT_API SandboxTokenSource final : public TokenSourceConfigurable {
292+
class LIVEKIT_API DevelopmentTokenSource final : public TokenSourceConfigurable {
293293
public:
294-
/// @brief Create a token source backed by the LiveKit Cloud sandbox token server.
294+
/// @brief Create a token source backed by the LiveKit Cloud development token server.
295295
///
296-
/// @param sandbox_id Sandbox identifier from LiveKit Cloud (surrounding whitespace is trimmed).
297-
/// @param options Sandbox token server options.
298-
/// @return A configurable token source backed by the sandbox token server.
299-
static std::unique_ptr<SandboxTokenSource> create(const std::string& sandbox_id,
300-
const SandboxTokenServerOptions& options = {});
296+
/// @param sandbox_id Development token server identifier from LiveKit Cloud (surrounding whitespace is trimmed).
297+
/// @param options Development token server options.
298+
/// @return A configurable token source backed by the development token server.
299+
static std::unique_ptr<DevelopmentTokenSource> create(const std::string& sandbox_id,
300+
const DevelopmentTokenServerOptions& options = {});
301301

302302
std::future<Result<TokenSourceResponse, TokenSourceError>> fetch(const TokenRequestOptions& options = {}) override;
303303

304304
private:
305-
explicit SandboxTokenSource(std::unique_ptr<TokenSourceConfigurable> endpoint);
305+
explicit DevelopmentTokenSource(std::unique_ptr<TokenSourceConfigurable> endpoint);
306306

307307
std::unique_ptr<TokenSourceConfigurable> endpoint_;
308308

309-
friend struct SandboxTokenSourceTestAccess;
309+
friend struct DevelopmentTokenSourceTestAccess;
310310
};
311311

312+
/// @deprecated Renamed to @ref DevelopmentTokenSource.
313+
using SandboxTokenSource [[deprecated("SandboxTokenSource is deprecated; use DevelopmentTokenSource instead")]] =
314+
DevelopmentTokenSource;
315+
316+
/// @deprecated Renamed to @ref DevelopmentTokenServerOptions.
317+
using SandboxTokenServerOptions
318+
[[deprecated("SandboxTokenServerOptions is deprecated; use DevelopmentTokenServerOptions instead")]] =
319+
DevelopmentTokenServerOptions;
320+
312321
/// @brief Decorator that adds JWT-aware caching to another configurable token source.
313322
///
314323
/// Wrap @ref CustomTokenSource, @ref EndpointTokenSource, or
315-
/// @ref SandboxTokenSource to reduce token fetch calls. A cached response is
324+
/// @ref DevelopmentTokenSource to reduce token fetch calls. A cached response is
316325
/// reused until the request options change or the JWT expires. Call
317326
/// @ref invalidate to force the next @ref fetch to bypass the cache.
318327
class LIVEKIT_API CachingTokenSource final : public TokenSourceConfigurable {

‎src/tests/unit/test_token_source.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ TEST(TokenSourceEndpointMockTest, SupportsGetMethod) {
207207
EXPECT_EQ(capture->method, "GET");
208208
}
209209

210-
TEST(TokenSourceSandboxMockTest, SetsSandboxHeaderAndResolvesUrl) {
210+
TEST(TokenSourceDevelopmentMockTest, SetsSandboxHeaderAndResolvesUrl) {
211211
auto capture = std::make_shared<CapturedRequest>();
212-
SandboxTokenServerOptions options;
212+
DevelopmentTokenServerOptions options;
213213
options.base_url = "https://cloud-api.livekit.io";
214-
auto source = SandboxTokenSourceTestAccess::create(
214+
auto source = DevelopmentTokenSourceTestAccess::create(
215215
" sandbox-123 ", options,
216216
makeStubTransport(capture, Result<std::string, std::string>::success(successResponseJson())));
217217

‎src/token_source.cpp‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,26 +201,25 @@ Result<TokenSourceResponse, TokenSourceError> EndpointTokenSource::fetchSync(con
201201
return parseTokenSourceResponseJson(http_result.value());
202202
}
203203

204-
std::unique_ptr<SandboxTokenSource> SandboxTokenSource::create(const std::string& sandbox_id,
205-
const SandboxTokenServerOptions& options) {
204+
std::unique_ptr<DevelopmentTokenSource> DevelopmentTokenSource::create(const std::string& sandbox_id,
205+
const DevelopmentTokenServerOptions& options) {
206206
auto resolved = resolveSandboxEndpoint(sandbox_id, {}, options.base_url);
207207
auto endpoint = EndpointTokenSource::create(std::move(resolved.url), std::move(resolved.options));
208-
return std::unique_ptr<SandboxTokenSource>(new SandboxTokenSource(std::move(endpoint)));
208+
return std::unique_ptr<DevelopmentTokenSource>(new DevelopmentTokenSource(std::move(endpoint)));
209209
}
210210

211-
SandboxTokenSource::SandboxTokenSource(std::unique_ptr<TokenSourceConfigurable> endpoint)
211+
DevelopmentTokenSource::DevelopmentTokenSource(std::unique_ptr<TokenSourceConfigurable> endpoint)
212212
: endpoint_(std::move(endpoint)) {}
213213

214-
std::unique_ptr<SandboxTokenSource> SandboxTokenSourceTestAccess::create(const std::string& sandbox_id,
215-
const SandboxTokenServerOptions& options,
216-
TokenSourceHttpTransport transport) {
214+
std::unique_ptr<DevelopmentTokenSource> DevelopmentTokenSourceTestAccess::create(
215+
const std::string& sandbox_id, const DevelopmentTokenServerOptions& options, TokenSourceHttpTransport transport) {
217216
auto resolved = resolveSandboxEndpoint(sandbox_id, {}, options.base_url);
218217
auto endpoint =
219218
EndpointTokenSourceTestAccess::create(std::move(resolved.url), std::move(resolved.options), std::move(transport));
220-
return std::unique_ptr<SandboxTokenSource>(new SandboxTokenSource(std::move(endpoint)));
219+
return std::unique_ptr<DevelopmentTokenSource>(new DevelopmentTokenSource(std::move(endpoint)));
221220
}
222221

223-
std::future<Result<TokenSourceResponse, TokenSourceError>> SandboxTokenSource::fetch(
222+
std::future<Result<TokenSourceResponse, TokenSourceError>> DevelopmentTokenSource::fetch(
224223
const TokenRequestOptions& options) {
225224
return endpoint_->fetch(options);
226225
}

‎src/token_source_internal.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ struct LIVEKIT_INTERNAL_API EndpointTokenSourceTestAccess {
4646
TokenSourceHttpTransport transport);
4747
};
4848

49-
/// @brief Test-only constructor access for @ref SandboxTokenSource.
49+
/// @brief Test-only constructor access for @ref DevelopmentTokenSource.
5050
///
51-
/// Builds a sandbox source whose underlying endpoint uses an injected stub
51+
/// Builds a development source whose underlying endpoint uses an injected stub
5252
/// transport, so the X-Sandbox-ID header and resolved URL can be asserted.
53-
struct LIVEKIT_INTERNAL_API SandboxTokenSourceTestAccess {
54-
static std::unique_ptr<SandboxTokenSource> create(const std::string& sandbox_id,
55-
const SandboxTokenServerOptions& options,
56-
TokenSourceHttpTransport transport);
53+
struct LIVEKIT_INTERNAL_API DevelopmentTokenSourceTestAccess {
54+
static std::unique_ptr<DevelopmentTokenSource> create(const std::string& sandbox_id,
55+
const DevelopmentTokenServerOptions& options,
56+
TokenSourceHttpTransport transport);
5757
};
5858

5959
/// @brief Build the standard LiveKit token-server JSON request body.

0 commit comments

Comments
 (0)