-
Notifications
You must be signed in to change notification settings - Fork 35
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
Generate a JWT with a RSA signature #166
Comments
Scratch my earlier comment. I think I've figured out that there is something wrong in the example that you've shared above. It would appear that the RSA private key that you're using in the example is not a DER encoded private key. The jsonwebtoken crate requires that you use DER format. Any JWT that uses the RS256 signature is going to require a key pair, not an individual file. I'm able to get around the error you've received above by using the #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
struct PrivateClaims {
company: String,
department: String,
}
let signing_secret = biscuit::jws::Secret::rsa_keypair_from_file(path).unwrap();
let expected_claims = ClaimsSet::<PrivateClaims> {
registered: biscuit::RegisteredClaims {
..Default::default()
},
private: PrivateClaims {
company: "company".to_string(),
department: "department".to_string()
}
};
let expected_jwt = JWT::new_decoded(From::from(
biscuit::jws::RegisteredHeader {
algorithm: biscuit::jwa::SignatureAlgorithm::RS256,
..Default::default()
}),expected_claims.clone());
let token = expected_jwt.into_encoded(&signing_secret).unwrap();
let token = token.unwrap_encoded().to_string(); |
Note that if you have a PEM string as in @stephane-ein's code, you can strip the first and last lines ( |
Hello,
I would like to generate a JWT with a RSA signature and I try to do the following :
But I got the following error :
I looked through the documentation and the code and it seems we cannot generate a secret from a RSA string value but only from a file (with
rsa_keypair_from_file
) or fromjwk::RSAKeyParameters
.Is there a way to generate an encoding key with RSA like this library https://github.com/Keats/jsonwebtoken ?
Regards
The text was updated successfully, but these errors were encountered: