Auth Class 3

 header is the most secured way compare to all we but we have to follow the syntax of this that is key ->"Autherization" and value -> "Bearer " with space


the token which we pass from body that is less secured 
avoid doing this 

HW  ? why bearer token is more secured 
cookie hijecking and token hijecking
https://chatgpt.com/share/6784be42-3904-8006-ae19-0009ed309190


Protected route is used for the purpose of authentication or authorization also  


how to sends token practically ???

1. cookie : - res.cookie.token      But for this there is pre requisite that you have to install cookie-Parser 
then only it will run

2. body :-  req.body.token     But for this there is also pre requisite that you have to install body parser (like express.json()) 


In below method you have to give space after Bearer       -- > Syntax :(

3. Header method :- there is 2 ways to doing this i. Raw method  Header Key Authorization token value
ii. ) Authorization token there is drop down option called bearer token you can do that 


like cookie we also have session concept 
but the only difference is session is stored in   server
and cookie is stored in client side 


cookies vs session GPTs response 

Cookies and sessions are both methods used to store data about a user, but they differ in several key ways:

1. Storage Location:

  • Cookies: Stored on the client-side (i.e., in the user's browser). The browser sends cookies with every HTTP request to the server.
  • Session: Stored on the server-side. The browser only sends the session ID (usually stored in a cookie) to the server, and the actual session data is kept on the server.

2. Data Size:

  • Cookies: Have a size limitation (typically around 4KB), meaning only small pieces of data can be stored.
  • Session: Can store larger amounts of data since the data is stored on the server and is not limited by client-side constraints.

3. Security:

  • Cookies: Less secure, as they reside on the user's machine and can be manipulated or intercepted if not properly protected (e.g., using secure and HTTP-only flags).
  • Session: More secure, as data is stored on the server and not directly accessible to the client. Only the session ID is shared between the server and the client.

4. Expiration:

  • Cookies: Can be set to expire after a certain time (e.g., after one day, one month, etc.), or can last for the duration of the browser session if no expiration is set.
  • Session: Typically expire when the user closes the browser or after a set inactivity period. However, servers can configure sessions to persist longer if needed.

5. Use Cases:

  • Cookies: Useful for persisting small bits of data like user preferences, remember-me functionality, and lightweight client-side data.
  • Session: Used to store sensitive data like user authentication, cart information, or other temporary data that should not be exposed to the client.

6. Speed:

  • Cookies: Accessing cookies is faster since they are stored on the client-side and don't require a round trip to the server, but they are sent with every HTTP request, potentially slowing down large-scale applications.
  • Session: Requires server-side access, so it might be slightly slower in terms of lookup but is more efficient for storing larger and sensitive data.

Summary:

  • Cookies are stored on the client and are best suited for small, non-sensitive data, while sessions store data on the server and are ideal for sensitive or larger-scale data that requires security.

Would you like a practical example of how to use cookies and sessions in code?

Comments

Popular posts from this blog

Edtech backend class 4

BD Class 4 Data Association

Authentication and autherization class 1