FacVain / dil-asistanim

1 stars 0 forks source link

Implement OAuth2 Google Authentication #38

Open alptekinsarilar opened 4 months ago

alptekinsarilar commented 4 months ago

Task Description

Implement OAuth2 Google Authentication for the web application using the Passport library. This will allow users to sign in using their Google accounts, providing a secure and convenient authentication method.

Implementation Details

Integrate the Passport library with the Express server. Configure Passport to use the Google OAuth2 strategy. Create environment variables to store Google client ID and client secret. Develop callback route to handle the response from Google's OAuth service. Ensure that the user's session is managed securely, storing only necessary information. Utilize user serialization and deserialization to maintain user state across sessions. Implement proper error handling for failed authentication attempts and other OAuth errors.

Design

Create passport.js file to configure Passport strategies. Add routes for initiating the Google OAuth process and handling the callback in auth.js. Use express-session or a similar middleware to handle session management. Set up environment variables in a .env file for storing Google client credentials and other configuration.

Tasks

Install Passport and Passport-Google-OAuth20 npm modules. Set up Google credentials (Client ID and Client Secret) in the Google Developer Console. Create passport.js with Google OAuth2 strategy configuration. Define the authentication route /auth/google to initiate the OAuth process. Define the callback route /auth/google/callback to handle OAuth responses. Implement user serialization/deserialization methods for session handling. Create corresponding methods in auth.js to manage user information post-authentication. Configure session management using express-session. Add environment variables for Google client ID, client secret, and callback URL to .env.

Expected Output

Users can start the OAuth2 authentication process by visiting /auth/google. Upon successful authentication, users are redirected back to the application with their session information. The user's profile information is stored in the session, and the user is considered 'logged in'. The application issues a session cookie to the client to maintain the authentication state.

Acceptance Criteria

The OAuth2 Google Authentication must be fully functional, allowing users to log in with their Google accounts. The application must handle errors gracefully, providing informative messages to users and logging details as necessary. Credentials and sensitive information must not be hardcoded and should be securely managed through environment variables. The user's password or sensitive OAuth details must not be stored in the database or session. The application must comply with Google's OAuth2 policies and any relevant security best practices.

Screenshots