Skip to content

Commit 3c37daa

Browse files
committed
Move Sandbox
1 parent eca4317 commit 3c37daa

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

Sources/LiveKit/Auth/Sandbox.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025 LiveKit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import Foundation
18+
19+
/// `Sandbox` queries LiveKit Sandbox token server for credentials,
20+
/// which supports quick prototyping/getting started types of use cases.
21+
/// - Warning: This token endpoint is **INSECURE** and should **NOT** be used in production.
22+
public struct Sandbox: TokenEndpoint {
23+
public let url = URL(string: "https://cloud-api.livekit.io/api/sandbox/connection-details")!
24+
public var headers: [String: String] {
25+
["X-Sandbox-ID": id]
26+
}
27+
28+
/// The sandbox ID provided by LiveKit Cloud.
29+
public let id: String
30+
31+
/// Initialize with a sandbox ID from LiveKit Cloud.
32+
public init(id: String) {
33+
self.id = id.trimmingCharacters(in: CharacterSet(charactersIn: "\""))
34+
}
35+
}

Sources/LiveKit/Auth/TokenSource.swift

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import Foundation
1818

1919
#warning("Fix camel case after deploying backend")
2020

21+
// MARK: - Token
22+
2123
/// `Token` represent the credentials needed for connecting to a new Room.
2224
/// - SeeAlso: [LiveKit's Authentication Documentation](https://docs.livekit.io/home/get-started/authentication/) for more information.
2325
public enum Token {
@@ -85,7 +87,7 @@ public enum Token {
8587
public typealias Literal = Response
8688
}
8789

88-
// MARK: - Provider
90+
// MARK: - Source
8991

9092
/// Protocol for types that can provide connection credentials.
9193
/// Implement this protocol to create custom credential providers (e.g., fetching from your backend API).
@@ -94,14 +96,13 @@ public protocol TokenSource: Sendable {
9496
}
9597

9698
/// `Token.Literal` contains a single set of credentials, hard-coded or acquired from a static source.
97-
/// - Note: It does not support refreshing credentials.
9899
extension Token.Literal: TokenSource {
99100
public func fetch(_: Token.Request) async throws -> Token.Response {
100101
self
101102
}
102103
}
103104

104-
// MARK: - Token Server
105+
// MARK: - Endpoint
105106

106107
/// Protocol for token servers that fetch credentials via HTTP requests.
107108
/// Provides a default implementation of `fetch` that can be used to integrate with custom backend token generation endpoints.
@@ -142,24 +143,6 @@ public extension TokenEndpoint {
142143
}
143144
}
144145

145-
/// `Sandbox` queries LiveKit Sandbox token server for credentials,
146-
/// which supports quick prototyping/getting started types of use cases.
147-
/// - Warning: This token endpoint is **INSECURE** and should **NOT** be used in production.
148-
public struct Sandbox: TokenEndpoint {
149-
public let url = URL(string: "https://cloud-api.livekit.io/api/sandbox/connection-details")!
150-
public var headers: [String: String] {
151-
["X-Sandbox-ID": id]
152-
}
153-
154-
/// The sandbox ID provided by LiveKit Cloud.
155-
public let id: String
156-
157-
/// Initialize with a sandbox ID from LiveKit Cloud.
158-
public init(id: String) {
159-
self.id = id.trimmingCharacters(in: CharacterSet(charactersIn: "\""))
160-
}
161-
}
162-
163146
// MARK: - Cache
164147

165148
/// `CachingTokenSource` handles caching of credentials from any other `TokenSource` using configurable store.

0 commit comments

Comments
 (0)