Good morning! I am trying to set up Joken to use JWT for server-client communication. I’ve tried following the example of bryanjos, but I get the message “invalid payload” when I try to verify the token. Below is a detailed explanation.
- Encoding
=========
def get_token(conn, _params) do
IO.puts "I will make a token for you ..."
current_user = conn.assigns.current_user
my_token = %{"user_id" => current_user.id}
|> token
|> with_validation("user_id", &(&1 == 1))
|> with_signer(hs256("yada82....))
|> sign
|> get_compact
render conn, "token.json", token: my_token
end
- Verifying
=========
def verify_token(token) do
token
|> token
|> with_validation("user_id", &(&1 == 1))
|> with_signer(hs256("yada82.....))
|> verify
- Error message
=============
%Joken.Token{claims: %{}, claims_generation: %{}, error: "Invalid payload",
errors: ["Invalid payload"], header: %{}, json_module: Poison,
signer: %Joken.Signer{jwk: %{"k" => "eWFkYTgyMDQzbVUsQGl6cTAjJG1jcV4mIUhGUXBucDhpLW5j",
"kty" => "oct"}, jws: %{"alg" => "HS256"}},
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo5fQ.GBDAhBAmVEcL9Ru-NvxVex9WmUFryRSvLiVIopPcVyg",
validations: %{"user_id" => {#Function<4.78128222/1 in LookupPhoenix.NoteApiController.verify_token/1>,
nil}}}