MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / decode_identity

Function decode_identity

crates/cli/src/util.rs:323–338  ·  view source on GitHub ↗
(token: &String)

Source from the content-addressed store, hash-verified

321}
322
323pub fn decode_identity(token: &String) -> anyhow::Result<String> {
324 // Here, we manually extract and decode the claims from the json web token.
325 // We do this without using the `jsonwebtoken` crate because it doesn't seem to have a way to skip signature verification.
326 // But signature verification would require getting the public key from a server, and we don't necessarily want to do that.
327 let token_parts: Vec<_> = token.split('.').collect();
328 if token_parts.len() != 3 {
329 return Err(anyhow::anyhow!("Token does not look like a JSON web token: {token}"));
330 }
331 let decoded_bytes = BASE_64_STD_NO_PAD.decode(token_parts[1])?;
332 let decoded_string = String::from_utf8(decoded_bytes)?;
333
334 let claims_data: IncomingClaims = serde_json::from_str(decoded_string.as_str())?;
335 let claims_data: SpacetimeIdentityClaims = claims_data.try_into()?;
336
337 Ok(claims_data.identity.to_string())
338}
339
340pub async fn get_login_token_or_log_in(
341 config: &mut Config,

Callers 7

execute_publish_configsFunction · 0.85
ensure_logged_outFunction · 0.85
execFunction · 0.85
select_databaseFunction · 0.85
execFunction · 0.85
exec_showFunction · 0.85

Calls 10

from_strFunction · 0.85
splitMethod · 0.80
try_intoMethod · 0.80
ErrFunction · 0.50
OkFunction · 0.50
collectMethod · 0.45
lenMethod · 0.45
decodeMethod · 0.45
as_strMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…