(token: &String)
| 321 | } |
| 322 | |
| 323 | pub 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 | |
| 340 | pub async fn get_login_token_or_log_in( |
| 341 | config: &mut Config, |
no test coverage detected
searching dependent graphs…