Skip to content

Commit b041fc7

Browse files
committed
refactor: extract access tokens into livekit-token
Moves access_token.rs, jwt_provider.rs and the test_token.txt fixture, plus the get_env_keys helper, into a new livekit-token crate. livekit-api re-exports it as `access_token`, which stays the documented path, so no consumer changes. Also fixes services-tokio and services-async, which used the access-token types without declaring the access-token feature: building with --no-default-features --features services-tokio failed to compile. The extraction forces the fix, since services/ can no longer reach the types any other way. Adds livekit-api/tests/backcompat_paths.rs, a compile-only guard on the re-export paths, since nothing else in the workspace imports them. Also records in the implementation plan that test_token.txt has to move with the token code; the plan had missed it, and cargo test -p livekit-token fails without it.
1 parent 5b8e805 commit b041fc7

21 files changed

Lines changed: 95 additions & 41 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
livekit-api: patch
3+
---
4+
5+
Moves access-token generation and verification into a new `livekit-token` crate.
6+
`livekit_api::access_token::*` continues to resolve to the same types via a
7+
re-export, so no consumer changes are needed.
8+
9+
Also fixes the `services-tokio` and `services-async` features, which used the
10+
access-token types without declaring the `access-token` feature. Building with
11+
`--no-default-features --features services-tokio` previously failed to compile.

Cargo.lock

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"livekit-ffi",
1010
"livekit-uniffi",
1111
"livekit-datatrack",
12+
"livekit-token",
1213
"livekit-token-source",
1314
"livekit-ffi-node-bindings",
1415
"livekit-net",
@@ -54,6 +55,7 @@ livekit = { version = "0.8.3", path = "livekit" }
5455
livekit-api = { version = "0.6.3", path = "livekit-api" }
5556
livekit-ffi = { version = "0.12.75", path = "livekit-ffi" }
5657
livekit-datatrack = { version = "0.1.13", path = "livekit-datatrack" }
58+
livekit-token = { version = "0.1.0", path = "livekit-token" }
5759
livekit-token-source = { version = "0.1.1", path = "livekit-token-source" }
5860
livekit-common = { version = "0.1.1", path = "livekit-common" }
5961
livekit-data-stream = { version = "0.1.2", path = "livekit-data-stream" }

knope.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ versioned_files = [
8585
changelog = "livekit-net/CHANGELOG.md"
8686
scopes = ["livekit-net"]
8787

88+
[packages.livekit-token]
89+
versioned_files = [
90+
"livekit-token/Cargo.toml",
91+
"Cargo.lock",
92+
{ path = "Cargo.toml", dependency = "livekit-token" },
93+
]
94+
changelog = "livekit-token/CHANGELOG.md"
95+
scopes = ["livekit-token"]
96+
8897
[packages.libwebrtc]
8998
versioned_files = [
9099
"libwebrtc/Cargo.toml",

livekit-api/Cargo.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ signal-client-tokio = ["signal-client", "livekit-net/native-tokio", "liveki
3131
signal-client-async = ["signal-client", "livekit-net/native-async", "livekit-runtime/async"]
3232
signal-client-dispatcher = ["signal-client", "livekit-net/native-dispatcher", "livekit-runtime/dispatcher"]
3333

34-
services-tokio = ["dep:reqwest", "dep:tokio", "tokio/time", "dep:livekit-runtime", "livekit-runtime/tokio"]
35-
services-async = ["dep:isahc", "dep:livekit-runtime", "livekit-runtime/async"]
36-
access-token = ["dep:jsonwebtoken", "dep:hmac", "dep:signature"]
34+
services-tokio = ["access-token", "dep:reqwest", "dep:tokio", "tokio/time", "dep:livekit-runtime", "livekit-runtime/tokio"]
35+
services-async = ["access-token", "dep:isahc", "dep:livekit-runtime", "livekit-runtime/async"]
36+
access-token = ["dep:livekit-token"]
3737
webhooks = ["access-token", "dep:serde_json", "dep:base64"]
3838

3939
# TLS Configuration
@@ -71,6 +71,7 @@ __rustls-tls = ["livekit-net?/__rustls-tls", "reqwest?/__
7171
[dependencies]
7272
livekit-net = { workspace = true, optional = true }
7373
livekit-protocol = { workspace = true }
74+
livekit-token = { workspace = true, optional = true }
7475
livekit-common = { workspace = true }
7576
thiserror = { workspace = true }
7677
serde = { workspace = true, features = ["derive"] }
@@ -85,12 +86,6 @@ pbjson-types = "0.6"
8586
serde_json = { workspace = true, optional = true }
8687
base64 = { version = "0.21", optional = true, features = ["std"] }
8788

88-
# access_token: HS256 only, via the in-crate HMAC CryptoProvider (jwt_provider.rs).
89-
# Dropping jsonwebtoken's rust_crypto bundle avoids linking RSA/EC/EdDSA.
90-
jsonwebtoken = { version = "10", default-features = false, optional = true }
91-
hmac = { version = "0.12", optional = true }
92-
signature = { version = "2", optional = true }
93-
9489
# signal_client
9590
livekit-runtime = { workspace = true, optional = true, default-features = false }
9691
tokio = { workspace = true, default-features = false, features = ["sync", "macros", "signal", "io-util", "net"], optional = true }

livekit-api/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
#![doc = include_str!("../README.md")]
1616

17+
// The token implementation lives in the livekit-token crate. This alias keeps
18+
// the historical `livekit_api::access_token::*` paths working, and remains the
19+
// documented, supported way to reach these types.
1720
#[cfg(feature = "access-token")]
18-
pub mod access_token;
19-
20-
#[cfg(feature = "access-token")]
21-
mod jwt_provider;
21+
pub use livekit_token as access_token;
2222

2323
#[cfg(any(feature = "services-tokio", feature = "services-async"))]
2424
pub mod services;
@@ -37,10 +37,3 @@ mod region;
3737

3838
#[cfg(feature = "webhooks")]
3939
pub mod webhooks;
40-
41-
#[allow(dead_code)]
42-
pub(crate) fn get_env_keys() -> Result<(String, String), std::env::VarError> {
43-
let api_key = std::env::var("LIVEKIT_API_KEY")?;
44-
let api_secret = std::env::var("LIVEKIT_API_SECRET")?;
45-
Ok((api_key, api_secret))
46-
}

livekit-api/src/services/agent_dispatch.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
// limitations under the License.
1414

1515
use super::{twirp_client::TwirpClient, ServiceBase, ServiceResult, LIVEKIT_PACKAGE};
16-
use crate::{
17-
access_token::{AccessTokenError, VideoGrants},
18-
get_env_keys,
19-
};
2016
use http::header::HeaderMap;
2117
use livekit_protocol as proto;
18+
use livekit_token::{get_env_keys, AccessTokenError, VideoGrants};
2219

2320
const SVC: &str = "AgentDispatchService";
2421

livekit-api/src/services/api_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use super::failover::FailoverConfig;
3535
use super::sip::CreateSIPParticipantOptions;
3636
use super::twirp_client::{ServerError, ServerResult, TwirpClient};
3737
use super::{LiveKitApi, ServiceError, SipCallError, LIVEKIT_PACKAGE};
38-
use crate::access_token::{AccessToken, VideoGrants};
38+
use livekit_token::{AccessToken, VideoGrants};
3939

4040
fn base_url() -> String {
4141
std::env::var("LK_TEST_SERVER_URL").unwrap_or_else(|_| "http://127.0.0.1:9999".to_owned())

livekit-api/src/services/connector.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use std::time::Duration;
1818

1919
use super::{ServiceBase, ServiceResult, LIVEKIT_PACKAGE};
2020
use crate::services::dial_timeout::DEFAULT_RINGING_TIMEOUT;
21-
use crate::{access_token::VideoGrants, get_env_keys, services::twirp_client::TwirpClient};
21+
use crate::services::twirp_client::TwirpClient;
22+
use livekit_token::{get_env_keys, VideoGrants};
2223

2324
const SVC: &str = "Connector";
2425

livekit-api/src/services/egress.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
use livekit_protocol as proto;
1616

1717
use super::{ServiceBase, ServiceResult, LIVEKIT_PACKAGE};
18-
use crate::{access_token::VideoGrants, get_env_keys, services::twirp_client::TwirpClient};
18+
use crate::services::twirp_client::TwirpClient;
19+
use livekit_token::{get_env_keys, VideoGrants};
1920

2021
#[derive(Clone, Copy, Debug, Default)]
2122
pub enum AudioMixing {

0 commit comments

Comments
 (0)