Skip to content

Commit 5f06521

Browse files
authored
add attributes to Claims and AccessToken (#693)
* add attributes to Claims and AccessToken * fix lint * make with_attributes more flexible * fix lint
1 parent 9907ad6 commit 5f06521

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

livekit-api/src/access_token.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::{
16+
collections::HashMap,
1617
env,
1718
fmt::Debug,
1819
ops::Add,
@@ -146,6 +147,7 @@ pub struct Claims {
146147
pub sip: SIPGrants,
147148
pub sha256: String, // Used to verify the integrity of the message body
148149
pub metadata: String,
150+
pub attributes: HashMap<String, String>,
149151
pub room_config: Option<livekit_protocol::RoomConfiguration>,
150152
}
151153

@@ -182,6 +184,7 @@ impl AccessToken {
182184
sip: SIPGrants::default(),
183185
sha256: Default::default(),
184186
metadata: Default::default(),
187+
attributes: HashMap::new(),
185188
room_config: Default::default(),
186189
},
187190
}
@@ -229,6 +232,17 @@ impl AccessToken {
229232
self
230233
}
231234

235+
pub fn with_attributes<I, K, V>(mut self, attributes: I) -> Self
236+
where
237+
I: IntoIterator<Item = (K, V)>,
238+
K: Into<String>,
239+
V: Into<String>,
240+
{
241+
self.claims.attributes =
242+
attributes.into_iter().map(|(k, v)| (k.into(), v.into())).collect::<HashMap<_, _>>();
243+
self
244+
}
245+
232246
pub fn with_sha256(mut self, sha256: &str) -> Self {
233247
self.claims.sha256 = sha256.to_owned();
234248
self

0 commit comments

Comments
 (0)