How can Angular verify user authentication in a BFF OAuth2 setup with Spring?

I’m working on an app and I’m stuck with the auth part. Here’s what happens:

  1. User clicks login on an Astro page
  2. Browser calls auth endpoint on Spring server
  3. Server makes a session cookie and empty Redis session
  4. Browser goes to Auth0 for login
  5. Auth0 sends browser back to Spring BFF
  6. BFF does token exchange with Auth0 and saves tokens in Redis
  7. BFF redirects to Angular landing page

Now I’m not sure how Angular can know if the user really logged in. The session cookie isn’t enough proof because it’s made before Auth0 login.

Right now, the cookie and Redis session last for 30 minutes (maybe 35 with some wiggle room).

Any ideas on how to handle this? Thanks!

hmm, interesting set up! have u considered a jwt token instead of only a session cookie? bff could make a signed jwt post-auth0 login with user info. angular decodes that token to verify auth status. what are ur thoughts?

In your BFF OAuth2 setup, Angular can verify user authentication through a combination of techniques. One effective approach is implementing a secure API endpoint on your Spring server specifically for authentication status. Angular can make an HTTP request to this endpoint upon landing, which checks the session cookie and validates it against the Redis session.

If the session is valid and contains Auth0 tokens, the server can respond with a success status and potentially some user info. Angular then uses this response to set its internal authentication state. To maintain security, ensure this endpoint is protected and returns minimal necessary information.

For ongoing validation, you could implement an HTTP interceptor in Angular to check authentication status before each API call, refreshing as needed. This server-validated mechanism prevents the client from directly accessing sensitive token data.

hey, ive dealt with this b4. u could add a /auth-status endpoint on ur spring server. when angular loads, hit that endpoint. server checks the cookie & redis session, confirms if tokens r there. if good, send back a simple ‘authenticated’ flag. angular can use that to set its auth state. ez peezy!