In a nutshell, Authentication asks who are you, Authorization asks are you allowed here?

Modern day Authentication techniques:

Auth techniques of the future:

Approaches for Authentication and Authorization today:

Difference between Session based Auth and JWT based Auth is that, Session based auth needed the server to be stateful to store the session ID, JWT allows stateless nature of the server as it encodes the user data within the token itself so no storage is necessary

  1. JWT (JSON Web Token)

    JWT is a token based stateless authentication mechanism where a json object containing the necessary user details is encoded with a secret key and sent to the user on signin. The subsequent user requests that require authentication is sent with the user token, the server then verifies it with the secret key and validates the user.

    A JWT token is usually encoded with base64 and another algorithm. A token consists with three main parts:

    The generated token is merged with these three parts with the following syntax:

    token = header.payload.signature
    

    the header and payload can be decoded easily, the authentication is verified using the signature, which is signed using the secret key, known only by the server. If the token is tampered in any way, the signature becomes invalid, and the user auth fails.

Sometimes a hybrid approach (stateful and stateless) is used where after successful jwt authentication, the server checks the database or any memory based storage (in case of redis) if the user is restricted (in case of RBAC) or banned for any shady activity or not. This is stateless authentication with stateful authorization.

This may seem like a defeat of purpose of stateless auth, but benefits of stateless auth still exists:

Cookies are a way of client side storage that the browser provides to store some relevant user data in a secured way. A server can store and access the cookies they have set, they cannot access any other server’s cookies. Tokens stateful or stateless are stored a cookie only till expiry if required.

Types of Authentication

  1. Stateful

  2. Stateless

  3. API Keys

  4. OAuth 2.0

  5. Stateful Authentication

stateful_auth.png

Note: The cookies are set as HTTP only, so they aren’t accessible by javascript/ scripts

  1. Stateless Authentication

stateless_auth.png