UrbanOS-Public / smartcitiesdata

The core micro services of UrbanOS as an umbrella project with component documentation
Apache License 2.0
61 stars 11 forks source link

SPIKE: Can auth0 be used with Andi UI? #904

Closed JulieMaterni closed 4 years ago

JulieMaterni commented 4 years ago

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:

bbrewer-forge commented 4 years ago

PR that will likely close for using Auth0 along with UberAuth https://github.com/smartcitiesdata/smartcitiesdata/pull/914

Main caveats:

Alternatives:

bbrewer-forge commented 4 years ago

Main example from Auth0 is here - https://auth0.com/blog/elixir-and-phoenix-tutorial-build-an-authenticated-app/

bbrewer-forge commented 4 years ago

Otherwise, in summary:

bbrewer-forge commented 4 years ago

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.

bbrewer-forge commented 4 years ago

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).

bbrewer-forge commented 4 years ago

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

bbrewer-forge commented 4 years ago

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

bbrewer-forge commented 4 years ago

Cards: