MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / jwt_decode

Function jwt_decode

aiscript-vm/src/stdlib/auth/jwt.rs:211–243  ·  view source on GitHub ↗
(state: &mut State<'gc>, args: Vec<Value<'gc>>)

Source from the content-addressed store, hash-verified

209}
210
211fn jwt_decode<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
212 if args.len() != 3 {
213 return Err(VmError::RuntimeError(
214 "decode() requires token string, secret key, and algorithm".into(),
215 ));
216 }
217
218 // Get token
219 let token = args[0].as_string()?;
220 let token_str = token.to_str().unwrap();
221
222 // Get secret key
223 let secret = args[1].as_string()?;
224 let secret_str = secret.to_str().unwrap();
225
226 // Get algorithm
227 let alg = args[2].as_string()?;
228 let algorithm = parse_algorithm(alg.to_str().unwrap())?;
229
230 // Create decoding key
231 let key = DecodingKey::from_secret(secret_str.as_bytes());
232
233 // Setup validation
234 let mut validation = Validation::new(algorithm);
235 validation.required_spec_claims.clear(); // Don't require any specific claims
236
237 // Decode token
238 let token_data: TokenData<Claims> = decode(token_str, &key, &validation)
239 .map_err(|e| VmError::RuntimeError(format!("JWT decoding error: {}", e)))?;
240
241 // Convert claims to AIScript object
242 Ok(claims_to_object(state.get_context(), token_data.claims))
243}
244
245fn create_access_token<'gc>(
246 state: &mut State<'gc>,

Callers

nothing calls this directly

Calls 8

RuntimeErrorClass · 0.85
parse_algorithmFunction · 0.85
claims_to_objectFunction · 0.85
lenMethod · 0.80
as_stringMethod · 0.80
to_strMethod · 0.80
as_bytesMethod · 0.80
get_contextMethod · 0.80

Tested by

no test coverage detected