1- What is passport-google-oauth20
?
2- Why do we use cookieParser
and encryptCookieNodeMiddleware
?
3- How do you let Express app use cookie middlewares (cookieParser, encryptCookieNodeMiddleware) with secret key for handling encryption of cookies *(answer might require code snippets)?
4- How to let your Express app use a middleware function that sends 401 (When not authenticated) error response code for auth errors and 500 (other errors) *(answer might require code snippets)?
5- In the auth.js
there is four paths:
/google, /me, /google/callback, /logout
can you guess what does each path refer too?
6- How do you let your Express app use JWT middleware to be used on all routes starting with /api?
a. How to exclude certain paths from the JWT authentication?
b. How to extract the JWT token from the request?
7- How do you Prepare Google Auth handling configuration?
8- How do you connect and configure Google OAuth 2.0 strategy on PassportJS instance?
9- How do you initialize PassportJS middleware?
1-
passport-google-oauth20
is a Node.js authentication middleware for Passport, which is an authentication middleware for Node.js. Specifically,passport-google-oauth20
allows you to authenticate users using Google OAuth 2.0 in your Node.js applications. With this middleware, you can easily integrate Google's OAuth 2.0 authentication mechanism into your application, allowing users to log in with their Google accounts. This is commonly used in web applications to provide users with a convenient and familiar way to sign in without requiring them to create and manage separate login credentials for your application.2- Using cookieParser and encryptCookieNodeMiddleware together provides a secure and convenient way to work with cookies in Node.js applications, ensuring both ease of use and protection of sensitive data
3- To enable an Express app to handle cookies securely with encryption using cookie-parser and express-encrypt-cookie middlewares:
Install the required packages: cookie-parser and express-encrypt-cookie.
Configure cookie-parser middleware to parse cookies, providing a secret key for cookie encryption.
Configure express-encrypt-cookie middleware to encrypt and decrypt cookies, using the same secret key.
Ensure that these middlewares are added to your Express app before any route handling.
Your app is now set up to handle cookies securely with encryption.
4- To enable your Express app to handle authentication errors with a 401 response code and other errors with a 500 response code, create a custom error handling middleware. This middleware checks the error type and sends the appropriate response code and message accordingly. Then, add this middleware to your Express app after other middleware and route handlers.
5- /google: Initiates Google OAuth 2.0 authentication.
/me: Retrieves user information from the server.
/google/callback: Callback URL for Google OAuth authentication.
/logout: Logs out the user from the application.
Abdulrahman muayid
shvan abdulhakeem
ahmed isam
payam R
ahmed jalal