Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 22, 2021 12:14 pm GMT

From Zero to Hero ( ) in Authentication | Part 1

Authentication

First focus on "WHAT".

Authentication is the act of proving an assertion, such as the identity of a computer system user. In contrast with identification, the act of indicating a person or thing's identity, authentication is the process of verifying that identity. It might involve validating personal identity documents, verifying the authenticity of a website with a digital certificate, determining the age of an artifact by carbon dating, or ensuring that a product or document is not counterfeit.

OKAY.! But it is kinda hard for me. Let's understand with a simple example. For example, you're Sheldon Cooper you go to the bank to withdraw money. You say to the cashier give me $5000, they were like "Who are you?? I don't know you so I can't". This happens because they don't know you, to identify you as a real holder of your bank account. They provided you a bank account number and pin/signature to identify you. When you give these details to the cashier, he will like "Thank you! Mr. Cooper, here is your $5000". So this shows that by giving the details it identifies you as the real holder of the bank account. So the process or action of verifying the identity of a user or process is Authentication.
Security

Types of Authentication

  1. Stateful
    • Cookie/Session Based Auth.
  2. Stateless
    • Basic Auth
    • JWT
    • OAuth

Stateful Authentication

Cookie
Stateful Authentication is a way to verify users by having the server or backend store much of the session information, such as user properties.
In this method whenever a client requests to the server, the request carries the unique-id provided by the server at the authentication time and this ID is matched against its identity provider (IdP).
Stateful authentication is also called session-based authentication or cookie-based authentication for the session information the server must store on the user.

Advantages

  • Revoke the session anytime.
  • Easy to implement and manage.

Disadvantages

  • Increasing server overhead: As the number of logged-in users increases, the more server resources are occupied.
  • Server has to store the session id which limits scalability.

Stateless Authentication

Token-based
Stateless authentication is a way to verify a user by storing its data on the client-side and signing it with some cryptographic signature. This signed data is known as a token. Whenever a client tries to request the server, the server verifies the signed token, check if the token is valid or not.

Advantages

  • Easy to scale
  • Lower server overhead: Server does not have to allocate resources to the client.

Disadvantages

  • Cannot revoke the session anytime: As token is stored at client side, server does not have any rights to delete the session.
  • Relatively complex to implement: It increases the technical complexity while implementing.
  • If a token gets steal before expiring and a hacker uses it, the server has no way to identify it. That's why token's expiry time should be less(<=15min).Man-In-Middle
StatefulStateless
Session information could be stolen It is impossible to steal session information from the session identifier because it is just an identifier associated with the session Session identifier contains all authentication information and it is possible to steal sensitive information, it is not encrypted.
Resource consuming When retrieving session information, service always gets access to session storage which causes additional resource consumption. The session identifier contains all session information.
Easy to implementWhen session information stored in an external database, there is a need to implement session database persistenceSession identifier contains all session information, there is no need to implement additional functionality
Easy to scaleWhile adding new instances, there is a need to implement additional scale to session storage as wellAdding new service instances does not require additional effort
Authentication token sizeIt is just an identifier, So size is small It contains a large amount of data, the authentication token also becomes large
Restrict access among different parts of an applicationIt is possible to configure the system so different parts of the system will only have access to the data necessary for their workAll parts of the system have access to all session data
Possibility to revoke sessionIt is possible to revoke a session at any timeSince the session token contains an expiration date, it is impossible to revoke the authentication session

Conclusion

Both approaches make sense, both have their advantages and disadvantages. Stateless authentication easier to implement and scale, but stateful authentication is more secure and easier to manage. In the next part, we'll understand each way of authentication like JWT, Cookie, OAuth, Etc.
Bye

Bibliography


Original Link: https://dev.to/kushagra_mehta/from-zero-to-hero-l-in-authentication-part-1-38od

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To