Hello, I'd like to propose adding a method for deserialization of the JwtPayload.
Background: I want to use josekit to verify the basic claims (exp,aud,sub,iss) and then deserialize multiple (other) claims that I expect to exist, using them as part of the API.
Doing that is currently very code intense and a lot of error handling:
let name: String = payload.claim("name")
.ok_or(AuthError::MissingClaim("name"))
.and_then(|v|josekit::Value::deserialize(v).map_err(AuthError::from))?;
let delete_after: Option<u32> = match payload.claim("delete_after").map(Deserialize::deserialize) {
None => None,
Some(Ok(i)) => Some(i),
Some(Err(_)) => return Err(AuthError::InvalidClaim("delete_after")),
};
As the JwtPayload contains the inner parts of json::Value::Object, I'd like to do something like
#[derive(Deserialize)]
struct ExpectedClaims {
name: String,
should_timeout: Option<u32>,
...
}
// handle invalid/missing claims at once
let my_claims: ExpectedClaims = payload.deserialize()?;
The less API intrusive way would be providing a into_inner(self) -> Map<String,Value> using the into_inner(self) -> Map<String,Value> function. I just found the function 😅. But I think this could be expanded by directly returning json::Value::Object.
let claims: josekit::Map<String,josekit::Value> = payload.into();
let val = serde_json::Value::Object(claims);
let my_claims: ExpectedClaims = serde_json::from_value(val)?;
Any thoughts ? Am I missing something here ?
If you would like to, I can open a PR for one of them.
Hello, I'd like to propose adding a method for deserialization of the
JwtPayload
.Background: I want to use josekit to verify the basic claims (exp,aud,sub,iss) and then deserialize multiple (other) claims that I expect to exist, using them as part of the API. Doing that is currently very code intense and a lot of error handling:
As the
JwtPayload
contains the inner parts ofjson::Value::Object
, I'd like to do something likeThe less API intrusive way would be
providing ausing theinto_inner(self) -> Map<String,Value>
into_inner(self) -> Map<String,Value>
function. I just found the function 😅. But I think this could be expanded by directly returningjson::Value::Object
.Any thoughts ? Am I missing something here ? If you would like to, I can open a PR for one of them.