Backend/Frontend - Platform - Authentication Setup
I've tried my best to make this really clean and simple to update and add to, I based the initial design off of passport.js
, but in a more customisable and flexible way. The goal is to enable easy swapping of authentication providers, allowing seamless integration of multiple OAuth platforms like Google
, GitHub
, and Discord
.
The idea is we define an Authenticator
class that manages multiple authentication strategies. For each of these strategies we generate routes and handle specific parsing. The authentication flow follows these steps:
- Login:
- The frontend navs to
/login/<strategy_name>
. - The backend retrieves the corresponding strategy and redirects the user to the provider’s authorisation URL.
- User grants Access:
- The user is redirected back to
/callback/<strategy_name>
with an authorisation code. - The backend exchanges the code for an access token and retrieves user information.
- The user is authenticated, saved logged into the system.
- Session Handling:
- The authenticated user session is stored with in-memory sessions, allowing seamless access to protected routes.
- I'd suggest moving it to a
redis
db but that may be overkill, good one to discuss.
- I'd suggest moving it to a
Edited by Liam Mcmanus