Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MiDo-kun/663fb01a62f159645528cd4c430ebb7a to your computer and use it in GitHub Desktop.
Save MiDo-kun/663fb01a62f159645528cd4c430ebb7a to your computer and use it in GitHub Desktop.
Open Authentication Notes

Questions

  1. How to send payload from frontend to backend.
  • Generate a unique session ID.
  • Store the unique session ID to the redis alongside user information and necessary information.
    • suggested key is session:${sessionId}
  1. How verify that the payload is valid.
  • Use the session ID in the authorization bearer that can be used to find in redis database and retrieve the neccessary information.
  1. How to save user information to redis.
  • redis.set(session:${sessionId}, JSON.stringify(userData));
  1. How to perform open authentication.
  • Use passport.js and its modules for specific authentication method.
  1. How does "remember me" works after being checked after submitting?
  • By extending the expiration date of the session ID.
  1. How to perform reverse proxy and use load balancer.
  • Reverse Proxy
    • Used as intermediary between client and a web server.
    • Can be used as a load balancer by redirecting request to the list of servers that is available.
  • Load Balancer
    • Express Gateway - An open source api gateway for express.js this can be used for microservices architectures.
    • PM2 - A node package manager that has a load balancing features. Note: Load balancing is performed inside the machine.

Task:

  • Received (Authorization bearer sessionID as a token)
  • Reponse JSON

start with

  • local register authentication
  • access protected routes
  • local login authentication

Thoughts:

  • SessionId generation

    • There is no specified rule on how the id is generated as long as it is unique.
  • Redis

    • Use ioredis-mock for testing redis on the local machine without creating a new connection(in memory).
    • Primary methods being used is set and get.
      • redis.set() requires a key and a value in string(if a json object is being used)
      • redis.get() request a key only return null if the key is not found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment