bcgov / cas-obps

0 stars 0 forks source link

Investigate session share between multiple frontend apps #256

Open pbastia opened 3 months ago

pbastia commented 3 months ago

Description:

There would be multiple ways of doing that. The team has used a postgres table in the past - that has the advantage of being able to implement RLS easily Are there any other options?

Acceptance Criteria:

Given When Then

Development Checklist:

Definition of Ready (Note: If any of these points are not applicable, mark N/A)

·Definition of Done (Note: If any of these points are not applicable, mark N/A)

Notes:

Potential session share solutions:

Leaning towards API Gateway to handle the session sharing. Could also add a DB session & RLS independently.

Dependencies

hannavovk commented 3 months ago

Dedicated meeting needed - @pbastia @shon-button @dleard @joshgamache

Sepehr-Sobhani commented 3 months ago

Sharing my thoughts:

Login and Token Exchange:

Backend Validation and Session Creation:

Session Exchange and Access Control:

shon-button commented 2 months ago

This spike is to explore upgrading authentication to auth.js v5, and to explore sharing JWT session state across microfrontends using Next.js Multi-zones feature.

Background

auth.js v5
Auth.js provides JWT-based user session strategy using JSON Web Tokens (JWT). When a user signs in, a JWT is created in a HttpOnly cookie. Making the cookie HttpOnly prevents JavaScript from accessing it client-side (via document.cookie, for example), which makes it harder for attackers to steal the value. In addition, the JWT is encrypted with a secret key only known to the server. So, even if an attacker were to steal the JWT from the cookie, they could not decrypt it. Combined with a short expiration time, this makes JWTs a secure way to create sessions. When a user signs out, Auth.js deletes the JWT from the cookies, destroying the session. This JWT session strategy allows logging in once, for the time the JWT is valid, so users do not have to log in every single time they visit the site.

Next.js multi zones A zone refers to a single Next.js app running on a server. Multiple Next.js apps can be combined together using the multi-zones feature so to appear as a unified application. For example, let’s say we have a Next.js application that consists of three different micro-frontends: a home app, a registration app, and a reporting app. You could define each of the separate micro-frontend app as a separate “zone”, and then, through configurations of .env, next.config.js, package.json, the user can navigate the apps as if it was a single, monolithic application allowing sharing of the authentication session between apps deployed on separate subdomains.

auth.js v5

Multi-zones

HOME APP

Image

Image

Image

REGISTRATION APP Image Image

REPORTING APP

Image Image