zooniverse / front-end-monorepo

A rebuild of the front-end for zooniverse.org
https://www.zooniverse.org
Apache License 2.0
104 stars 29 forks source link

Implement server-side authentication #1306

Open rogerhutchings opened 5 years ago

rogerhutchings commented 5 years ago

We need to handle auth on the server. Specifically, picking up user project preferences for determining workflow selection etc.

cc #365 #1132

Time estimate: 6 weeks

rogerhutchings commented 5 years ago

Okay, made some progress on this today with @camallen, to the point where I got a cookie passed along with the page request :tada:

Steps to reproduce

Notes / thoughts

camallen commented 5 years ago

Noting that once i've solved https://github.com/zooniverse/Panoptes/issues/3123 you won't need to run your own API to test this. Please ping me if you need help.

camallen commented 4 years ago

Ok - SSR authentication update, i’ve modified the frontend.preview.zooniverse.org domain to proxy /users/sign_in & oauth/tokens requests to the production API*

In order to test the SSR cookies are being sent to the front end apps, you’ll need to visit https://frontend.preview.zooniverse.org/projects/nora-dot-eisner/planet-hunters-tess?panoptes-api-host=https://frontend.preview.zooniverse.org (or rebuild the underlying code to use this domain for auth host on preview site).

Once there you will be able to sign in normally (to Production API) and the correct session cookie will set in the browser, thus also sent to the SSR app on reload etc

Then that session cookie can be used to to get a JWT and interact with the API for authenticated page content creation on the server 🎉

You can check this by looking at your reload HTML page request headers and see the cookies being sent on the original request (also inspect your cookies)

The production www.zooniverse.org cloud front behaves the same as preview.* and as the auth host is www.zooniverse.org this will work out of the box on that site.

Please reach out if you have questions etc.

* This is a little confusing as by default the deployed code on that domain (PFE) talks to staging, interestingly the deployed FE-project|content-app talk to production (these have different CloudFront paths proxying to the different apps).

These rebuilt project-app is available at /projects/nora-dot-eisner/planet-hunters-tess The CF upstream API destination (production) is most likely to change longer term but it works in the short term for the testing the main deployed project we have.

The PJC code will have to change to sort the CFEs so will think about how we can help with this issue as well. It may be that we may have to look at frontend.preview.zooniverse.org -> production APIs and/or frontend-staging.preview.zooniverse.org -> staging (edited)