-
Notifications
You must be signed in to change notification settings - Fork 255
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
Translate Example to Elixir #104
Comments
@nelsonic I have been reviewing the code in I think I have understood the gist of what is happening for the most part. This is all straightforward enough to recreate in elixir (even without a phx server). I have found a few packages/modules that are capable of creating JWTs in elixir. They are:
So far I have only used {:ok, token, _} = LearnJwt.Token.generate_and_sign(%{user_id: 1})
IO.inspect(token)
LearnJwt.Token.verify_and_validate!(token)
|> IO.inspect(label: "===> ") logs....
The config :joken,
default_signer: "secret",
testing: "test"
{:ok, token2, _} = LearnJwt.Token.generate_and_sign(%{user_id: 1}, :testing)
LearnJwt.Token.verify_and_validate!(token2) we get the following error... This means that we can use these functions to create and verify our JWTs. The part I am not entirely sure how to replicate is this, sending the JWT to the client. I can send it to the client in the assigns argument of the render function like so... render(conn, "index.html", jwt: token) at which point we could store it in I haven't yet touched on how we will send the JWT back to the server but I assume that we can do this with js on the front end if there is not a "clean" way to do it using phoenix forms. (I have not seen one example of a phoenix application using phoenix templating to send jwt back to the server which leads me to think it is not "clean") |
@RobStallion please consider using https://hexdocs.pm/plug/Plug.Conn.html |
Have you had a read of: https://hexdocs.pm/plug/Plug.Session.COOKIE.html ? 💭 |
Taking a short break from this for now. Will come back to in a couple of days |
This tutorial is great for JavaScript but it would be amaze to have it in Elixir from first principals to understand how to authenticate a request using JWT.
Todo
For a basic Elixir Web Server, see: https://github.com/dwyl/hits-elixir (no phoenix! 😮)
elixir-example.md
@RobStallion we briefly discussed this on the call today.
Please add any other acceptance criteria you feel are relevant.
The text was updated successfully, but these errors were encountered: