Closed JulieMaterni closed 4 years ago
PR that will likely close for using Auth0 along with UberAuth https://github.com/smartcitiesdata/smartcitiesdata/pull/914
Main caveats:
Alternatives:
Main example from Auth0 is here - https://auth0.com/blog/elixir-and-phoenix-tutorial-build-an-authenticated-app/
Otherwise, in summary:
It turns out that the above only handles authentication. As for authorizing each request - we would need to use Guardian still similar to how we do with Disco API
https://hexdocs.pm/ueberauth/Ueberauth.Auth.html#t:t/0
Basically, when we do finish the authentication we can get the JWT from auth_returned_by_auth0.credentials.token
and then attach that to the conn
via Guardian's standard functions. For a live view, this can then be attached to the socket on view mount
so as to be attached as data on the socket. We can then examine the JWT with the key verifier on that socket just like we do with Guardian in Disco API, with the only major difference being that it's not a Plug
at that point as LiveView doesn't utilize plugs.
The only major gotcha with using Guardian in this case, is that we need to store the JWT in both the LiveView sockets on mount AND in a session cookie (which would be reasonable for a server-side app, but we would want CSRF tokens, at a minimum for this).
Looks like our browser (server-side) pipeline is already set up for CSRF via hidden inputs on the forms
https://angelika.me/2019/12/31/csrf-protection-in-phoenix/
We would also need to fix-up our links to be HTML links instead of buttons for some of this to work.
Otherwise, the API itself would just be covered by a required JWT in the header as a Bearer at that point
The example PR for this uses the Phoenix Session that we already have, as that meshes very easily with the LiveView mount. https://github.com/smartcitiesdata/smartcitiesdata/pull/914
Cards:
auth/auth0
and auth/auth0/callback
endpoints) https://auth0.com/blog/elixir-and-phoenix-tutorial-build-an-authenticated-app/ - tech note about an "andi" API/audience in addition to the current discovery_api one
As a data contributor or curator, I want to have one account to share and view my datasets so that I have an easy to use, streamlined experience.
ACs: