erlang-jose
erlang-jose copied to clipboard
JWT - Invalid signature! when using es256
I`m creating a push notification for Apple (APNs). Code is simple:
-spec generate_token(binary(), binary(), string()) -> binary().
generate_token(TeamId, KeyId, KeyPath) ->
PrivateJWK = jose_jwk:from_pem_file(KeyPath),
JWK = jose_jwk:to_map(PrivateJWK),
JWS = #{
<<"alg">> => <<"ES256">>,
<<"kid">> => KeyId
},
JWT = #{
<<"iss">> => TeamId,
<<"iat">> => apns_utils:epoch()
},
Signed = jose_jwt:sign(JWK, JWS, JWT),
{_, Token} = jose_jws:compact(Signed),
Token.
Key is *.p8
But apns answer with:
{403,[{<<"apns-id">>,<<"1294465C-E2AA-61D5-E49A-72E1A3C70BDC">>}],#{<<"reason">> => <<"InvalidProviderToken">>}}
I went to https://jwt.io and got the same answer.
What I do wrong?
@Akick did you ever figure out the issue? I have the same problem.
@jbosse Yup. I used https://github.com/G-Corp/jwerl