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

Function build_claims

aiscript-vm/src/stdlib/auth/jwt.rs:77–112  ·  view source on GitHub ↗
(claims_obj: &GcRefLock<'gc, Object<'gc>>)

Source from the content-addressed store, hash-verified

75}
76
77fn build_claims<'gc>(claims_obj: &GcRefLock<'gc, Object<'gc>>) -> Result<Claims, VmError> {
78 let mut claims = Claims::default();
79 let fields = &claims_obj.borrow().fields;
80 for (key, value) in fields {
81 let key_str = key.to_str().unwrap();
82 match key_str {
83 "iss" => claims.iss = Some(value.as_string()?.to_string()),
84 "sub" => claims.sub = Some(value.as_string()?.to_string()),
85 "aud" => claims.aud = Some(value.as_string()?.to_string()),
86 "exp" => claims.exp = Some(value.as_number()? as i64),
87 "nbf" => claims.nbf = Some(value.as_number()? as i64),
88 "iat" => claims.iat = Some(value.as_number()? as i64),
89 "jti" => claims.jti = Some(value.as_string()?.to_string()),
90 // Handle custom claims
91 _ => {
92 let json_value = match value {
93 Value::String(s) => serde_json::Value::String(s.to_string()),
94 Value::Number(n) => {
95 serde_json::Value::Number(serde_json::Number::from_f64(*n).unwrap())
96 }
97 Value::Boolean(b) => serde_json::Value::Bool(*b),
98 Value::Nil => serde_json::Value::Null,
99 _ => {
100 return Err(VmError::RuntimeError(format!(
101 "Unsupported claim value type for key: {}",
102 key_str
103 )));
104 }
105 };
106 claims.extra.insert(key_str.to_string(), json_value);
107 }
108 }
109 }
110
111 Ok(claims)
112}
113
114fn claims_to_object(ctx: Context, claims: Claims) -> Value {
115 let mut obj = Object::default();

Callers 1

jwt_encodeFunction · 0.85

Calls 5

RuntimeErrorClass · 0.85
to_strMethod · 0.80
as_stringMethod · 0.80
as_numberMethod · 0.80
borrowMethod · 0.45

Tested by

no test coverage detected