Thanks easco… yeah, I have no desire to tie into the whole config stuff just to verify that Google’s token is valid, but I can’t seem to make much work in the Joken package – I’ve tried variants of your solution, but no dice. I’m not sure where Joken.verify(iam_token, signer, [])
comes from, but it generates an error for me:
function Joken.Signer.verify/3 is undefined or private.
I am assuming that Google’s certs listed at https://www.googleapis.com/oauth2/v1/certs are PEMs, but I’m pretty much just guessing at the exact algorithm. The docs don’t appear to list the supported algorithms, but one of the error messages states that the possible values are
[“HS256”, “HS384”, “HS512”, “RS256”, “RS384”, “RS512”, “ES256”, “ES384”, “ES512”, “PS256”, “PS384”, “PS512”, “Ed25519”, “Ed25519ph”, “Ed448”, “Ed448ph”]
However, trying to use some of these comes up with errors that the algorithm isn’t recognized. So that leaves me pretty confused. The best I’ve been able to do is to get a {:error, :signature_error}
Converting the Google RSA cert into an Elixir data structure looks like this:
keys = %{
keys: [
%{
alg: "RS256",
n: "mSLCSG1hK28xrzcSfgbvRinkIRjecBlwsQggynHppHiiT6I80waivIqTJBSFYyVuRCAHXi6apSsL5FUWKd42GOhVUayIyzvuz1CqTuh5a9ACXaJjEVLUFO39QfXxWrxhpSJCTN9aMkdtoV1QJqfAd3IF9MYwfojsoEn3d5XX5TX4RxqZ9-HGbgSLsRuAzFIg9NxxfTYhbECBskhhR4RIcam-1T52FafmK2LMiuIEDPiVg6LvAqWi8gdMRd8WhiP_ZIRJTCH4C0NFKmw1PZyKadVxvwg97vwPTF8qkFdwJ_kjQAMmq77PxankluAkfWjFqbD4JepO4HH3aJvU8Sl_Ow",
use: "sig",
kid: "08d3245c62f86b6362afcbbffe1d069826dd1dc1",
e: "AQAB",
kty: "RSA"
},
%{
alg: "RS256",
n: "uS9Iep_r83oLpfnMXLnB5a8IVUP7ZRreM1rxNWYnaqEQr1NfRisyIi4cYG7KbWiuLCmRQOD7ybhpdHCcN9ty5evz4irWT5hIa98Jr3a2BISTskBbPmBgUR3_TuQ_fvxeQYCCETJUcho5gXK-yeDWJwcD2iwqpVzIZHz8BBe5AYFUlJMzwgzYMe9aqoOEWVv__Gd7Z_kaz5pa0lOsWUUPNFmeW4e4rtNvosx7ItyyyghIyG2KX-0phOgbfzG6Ub6qA9upBYK9KBtjcoe1ciV-Yn_3HaS5PlugYTo1zYnng1mW7UP5A_QT_HgDqD1clcz0WIEL6usVMRay87ECEmOhrw",
use: "sig",
kid: "b15a2b8f7a6b3f6bc08bc1c56a88410e146d01fd",
e: "AQAB",
kty: "RSA"
}
]
}
Joken.Signer.verify(idtoken, Joken.Signer.create("RS256", keys))
But this too throws an error:
Joken.Signer.verify(idtoken, Joken.Signer.create("RS256", keys))
** (FunctionClauseError) no function clause matching in JOSE.JWK.from_record/1