-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring config/passport.js #1279
Comments
I relatively need to open source and contributions, but if you can guide me how to make the required changes, i can work and deliver excellent results. |
Hey @YasharF |
No assignment at this point. Please discuss as you may see fit. |
We could improve Passport.js OAuth setup by organizing code into smaller parts, making it easier to manage multiple login options. Create a common function to handle different services and set up a way to easily add new logins. This will simplify the process and make it smoother to expand login choices. |
Can someone check on the pr #1293 , i focused on importing the already defined "handleservice" function and utilizing it within Passport authentication strategies. |
hey @YasharF You can assign this to me The common approach is to handle each strategy separately, but there's an efficient way to centralize the logic to avoid repetition. You can create a common function to handle authentication across different providers. This function will handle linking accounts, checking if the user already exists, and managing tokens for various providers. Here's a simplified overview of how this works: Setup the strategies: Use passport.use for each provider (Google, Facebook, etc.), passing in the necessary credentials from .env and callback URLs. Common handling logic: Create a function that processes the authentication callback. This function checks if the user is logged in, links accounts if needed, or creates a new user if it’s a new login. Serialize and deserialize user: Store the user in the session using serializeUser and retrieve them using deserializeUser. config/passport.js
routes/auth.js
User Model Update
Environment Variables
|
I would like to work on this , Please assign me this issue under hacktoberfest 2024. |
I have raised a PR for this - #1310 Can you please check this and give me some inputs? |
NOTE: Prior to any PRs the potential design and implementation needs to be discussed in this issue as this is not a minor code change. Please make sure you have a good understanding of oAuth 2.0 including refresh tokens, etc. prior to any work on this issue.
Background: At a higher level, the strategies in passport.js seem to be following similar patterns.
Problem: Maintenance of the strategies when there is a change to the underlying libraries is cumbersome. We can also end up with bugs because a fix may have been applied to most of the strategies but one or two may have been missed. To provide an example, the passport,js mongoose 7 upgrade resulted in a ~900 line diff, but at the core of it, it was the same change getting repeated in each strategy: 55defd3#diff-fa60852f5a2e88327803171e7f8972c7799de05a17566b46e958f27c4c7b965e
Potential solution:
We refactor the code so there is a core generic routine for handling oAuth, which uses configs for each oAuth provider. This potential solution can also allow us or users to easily add (or remove) oAuth providers without worrying about potential token handling bugs in specific implementations.
NOTE: Prior to any PRs the potential design and implementation needs to be discussed in this issue as this is not a minor code change. Please make sure you have a good understanding of oAuth 2.0 including refresh tokens, etc. prior to any work on this issue.
The text was updated successfully, but these errors were encountered: