I need some help with a demo project I am working on to showcase Google OAuth login using rocket
and jwt
. I'm implementing jwt::Store
for a custom tuple type that I have created which wraps a HashMap<String, PKeyWithDigest>
.
The implementation of jwt::Store
looks like this:
/// Response from www.googleapis.com/oauth2/v1/certs containing key IDs to PEM-encoded certificates.
#[derive(Deserialize)]
struct GoogleCertsResponse(HashMap<String, String>);
/// Key-store for Google JWT signing keys.
struct JwtKeystore(HashMap<String, PKeyWithDigest<Public>>);
impl TryFrom<GoogleCertsResponse> for JwtKeystore {
type Error = openssl::error::ErrorStack;
fn try_from(value: GoogleCertsResponse) -> Result<Self, Self::Error> {
let mut result = HashMap::with_capacity(value.0.len());
for (k, v) in value.0.into_iter() {
result.insert(
k,
PKeyWithDigest {
key: X509::from_pem(v.as_bytes())?.public_key()?,
digest: MessageDigest::sha256(),
},
);
}
Ok(Self { 0: result })
}
}
impl Store for JwtKeystore {
type Algorithm = PKeyWithDigest<Public>;
fn get(&self, key_id: &str) -> Option<&Self::Algorithm> {
self.0.get(key_id)
}
}
I'm then attempting to use this code like so:
let token: Result<Token<JwtHeader, JwtClaims, Verified>, jwt::Error> =
form.credential.verify_with_store(keystore.inner());
keystore
is a JwtKeystore
and the error message is:
error[E0277]: the trait bound `&str: VerifyWithStore<Token<serde_json::Value, serde_json::Value, Verified>>` is not satisfied
--> src/lib.rs:131:25
|
131 | form.credential.verify_with_store(keystore.inner());
| ^^^^^^^^^^^^^^^^^ the trait `VerifyWithStore<Token<serde_json::Value, serde_json::Value, Verified>>` is not implemented for `&str`
|
= help: the following implementations were found:
<&'a str as VerifyWithStore<C>>
<&'a str as VerifyWithStore<Token<H, C, Verified>>>
I'm having trouble understanding this issue. The pull request is naftulikay/rocket-oauth-jwt-demo#1. This code was previously working:
let token: Token<JwtHeader, JwtClaims, Unverified> =
Token::parse_unverified(form.credential).unwrap();
How can I parse this error to read the docs to understand what is expected and how to change my code? I'd like to be more confident in diagnosing and fixing these issues on my own.