-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implementation of serde::de::Deserialize
is not general enough
#91
Comments
Hey, I am very very new to Rust and I am also using this library and saw your issue. The solution in this case is to declare your
Unfortunately I cannot in detail articulate yet why exactly Furthermore in your code this part is also problematic: let format_the_u8 = format!("b{}", secret_key);
let new_key: Hmac<Sha256> = Hmac::new_from_slice(&format_the_u8.as_bytes()).unwrap(); and results in a Here's a working modification of your code: fn main() {
let user = UserForAuth{
id: String::from("some_id"),
nickname: String::from("some_nickname"),
email: String::from("some_email"),
role: String::from("some_role"),
};
let tok = create_jwt(user, b"some-secret");
let u = verify_jwt_and_return_values(tok.as_str(), "some-secret").unwrap();
println!("{:?}", u);
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct UserForAuth {
pub id: String,
pub nickname: String,
pub email: String,
pub role: String,
}
pub fn create_jwt(user_struct: UserForAuth, secret_key: &[u8]) -> String {
let jwt_key: Hmac<Sha256> = Hmac::new_from_slice(secret_key).unwrap();
let mut new_claim = BTreeMap::new();
new_claim.insert("user", user_struct);
return new_claim.sign_with_key(&jwt_key).unwrap();
}
pub fn verify_jwt_and_return_values(jwt_value: &str, secret_key: &str) -> Option<UserForAuth> {
let new_key: Hmac<Sha256> = Hmac::new_from_slice(secret_key.as_bytes()).unwrap();
println!("{:?}", new_key);
let result: Result<BTreeMap<String, UserForAuth>, Error> = jwt_value.verify_with_key(&new_key);
match result {
Ok(existing_claim) => Some(existing_claim["user"].clone()),
Err(e) => {
println!("{}", e);
None
}
}
} Hope it helps! |
it's interesting to see. This error is most mysterious and implicit error in rust i ever seen, definitely contrary to rust's error policy. I was changed another package to solve my problem and i could implemented it successfully. I don't think to use this package anymore. |
Hello, i want to make an authentication flow with your package but i take that error.
My related codes like this:
in models crate:
in authlogic crate:
and i take that error:
error: implementation of
serde::de::Deserialize
is not general enough--> authlogic\src\lib.rs:22:63
|
22 | let existing_claim: BTreeMap<&str, models::UserForAuth> = jwt_value.verify_with_key(&new_key).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of
serde::de::Deserialize
is not general enough|
= note:
BTreeMap<&str, UserForAuth>
must implementserde::de::Deserialize<'0>
, for any lifetime'0
...= note: ...but it actually implements
serde::de::Deserialize<'1>
, for some specific lifetime'1
error: could not compile
authlogic
(lib) due to previous errorSo how do i fix that error?
The text was updated successfully, but these errors were encountered: