-
Notifications
You must be signed in to change notification settings - Fork 1
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
JWT authentication #3
Conversation
achouippe
commented
Jul 17, 2024
•
edited
Loading
edited
- Add JWT authentication to the public and internal apis,
- Rework the contracts of the public and internal apis.
- Rework the way to configure JWT authentication settings per environment.
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
lib/neurow/jwt_auth_plug.ex
Outdated
def init(options), do: options | ||
|
||
def call(conn, options) do | ||
case jwt_token_from_request(conn) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to use what seems to be idiomatic of Elixir, but I wonder if I should not use a try / rescue instead.
|
||
get "v1/subscribe" do | ||
case conn.assigns[:jwt_payload] do | ||
%{"iss" => issuer, "sub" => sub} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The topic name is expected in the sub claim of the jwt token.
The idea here is to use the issuer as a way to isolate multiple systems that use neurow for each others.
post "v1/publish" do | ||
issuer = conn.assigns[:jwt_payload]["iss"] | ||
|
||
topic = "#{issuer}-#{conn.body_params["topic"]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topic = "#{issuer}-#{conn.body_params["topic"]}" | |
topic = "#{issuer}:#{conn.body_params["topic"]}" |
get "v1/subscribe" do | ||
case conn.assigns[:jwt_payload] do | ||
%{"iss" => issuer, "sub" => sub} -> | ||
topic = "#{issuer}-#{sub}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topic = "#{issuer}-#{sub}" | |
topic = "#{issuer}:#{sub}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered it, but we need to discuss it. Where to we set the topic & sub topic part ? The sub will eventually contains something like user:123
. By generating a topic name like issuer-user:123
the sub topic is used for the record id.
But the purpose of topic / subtopic in the phoenix pubsub is not totally clear for me for now.
…rs is set to false