atomicdata-dev / atomic-data-browser

This repo is no longer used! Code is moved to Atomic-Server
https://github.com/atomicdata-dev/atomic-server/issues
MIT License
55 stars 9 forks source link

Cross domain authentication (using cookies?) #278

Open joepio opened 1 year ago

joepio commented 1 year ago

Since #241 we have cookie-based authentication. This solved the issue of opening images that require authentication. However, this approach only works for images on the same domain. If you'd visit example.com, where you'd login, and show a private image from atomicdata.dev, you would not be able to see it, because example.com's JS will not be able to set a cookie due to security.

So how do we deal with this?

Set a cookie server-side

This is the de facto standard way of doing things. Servers control authentication and identies. We could add a /cookie endpoint, which returns a server-signed cookie (JWT) that proves to the server that the user is authenticated.

This approach is feasible, but it also feels like unnecessary complexity. Since the client owns the private key (and not the server), there is no need for the server to sign anything. It just adds another point of failure.

Add a query parameter with some token

Instead of requesting atomicdata.dev/myimage.png, you'd request atomicdata.dev/myimage.png?authResource=asdf. The client adds this token, which encodes an Authentication Resource (i.e. the same content as the cookie)

This means the client will need to add this query param to all image URLs.

Proxy all the images

Instead of requesting atomicdata.dev/myimage.png, we'd request example.com/proxy?url=atomicdata.dev/myimage.png. The proxy could then re-use the Authentication Resource created by the client, and gain access to the image.

This approach has a couple of downsides: