reboottime / WebDevelopment

Some notes, thoughts and articles aggregated here about UI/UX and web development.
6 stars 0 forks source link

Revisit Authentication Common Sense as a Web developer #175

Open reboottime opened 1 year ago

reboottime commented 1 year ago

When we use various applications and websites, three essential security steps are continuously at play:

Bellow is a diagram where these methods applied in a typical website architecture

Security



Overview

This article revisits the authentication related common senses.

reboottime commented 1 year ago

Password Authentication

Sharing Passwords

reboottime commented 1 year ago

HTTP Basic Authentication

The flow of HTTP Basic Authentication

HTTP Basic Authentication



Session-Cookie Authentication

Session-cookie authentication addresses HTTP basic access authentication's inability to track user login status. A session ID is generated to track the user's status during their visit. This session ID is recorded both server-side and in the client’s cookie.

Bellow is the session cookie based interaction flow

interaction flow



JWT Token

JWT token interaction flow and common sense



JWT VS Session tokens

JSON Web Tokens (JWTs) and session tokens are both mechanisms used for authentication and authorization in web applications, but they have distinct characteristics and use cases. Here's a comparison of JWT tokens and session tokens:

JWT (JSON Web Token):

  1. Self-Contained: JWTs are self-contained tokens that contain information (claims) in a structured format, typically in JSON. These claims can include user identity, access rights, and other relevant data.

  2. Stateless: JWTs are inherently stateless, meaning the server does not need to maintain any session information. All the necessary information is within the token itself.

  3. Decentralized: JWTs can be generated and signed by an authentication provider or Identity Provider (IdP) but can be verified by any party with the appropriate key. This decentralization can simplify authentication across different services.

  4. Scalability: JWTs are suitable for distributed and microservices architectures, as they do not rely on a centralized session store. Each service can independently verify JWTs.

  5. Expiration: JWTs can include an expiration time (exp claim) to control their validity. Once a JWT expires, it is no longer considered valid.

  6. Use Cases: JWTs are commonly used in Single Sign-On (SSO), OAuth 2.0 authorization, and secure data transmission. They are well-suited for modern, stateless, and distributed application architectures.

Session Token:

  1. Server-Side State: Session tokens typically rely on server-side state management. When a user logs in, a session token is created, and a session is established on the server to store user-specific data and maintain state.

  2. Cookies or URL Parameters: Session tokens are often stored in cookies or passed as URL parameters to maintain user sessions across multiple requests. Cookies are the most common method for web applications.

  3. Session Management: The server manages user sessions and session tokens, tracking user activity, session timeouts, and session cleanup.

  4. Revocation: Session tokens can be revoked server-side, which allows administrators to log out users or terminate their sessions remotely.

  5. Use Cases: Session tokens are commonly used in traditional server-side web applications, where maintaining server-side state is necessary. They are well-suited for monolithic architectures.

Considerations:

In summary, JWTs and session tokens have different characteristics and are used in various contexts based on the specific needs of the application. The choice between them depends on factors such as the architecture, security requirements, and scalability of your application.

reboottime commented 1 year ago

OAuth 2.0 Standard Based Authentication

OAuth 2.0 is a protocol that allows you to grant your application permission to access your data on another application.

Let's use the Terrible Pun Joke case, to illustrate how OAuth 2.0 works.

There are three main parties involved in OAuth 2.0:

Terrible Pun Jokes Application Perspective

From the perspective of the Terrible Pun Jokes application, there is a partnership between itself and the gmail client authorization server.

Authorization Server Partnership

User's Journey Using Terrible Pun Jokes

Below is the user's journey when using the Terrible Pun Jokes application:

User's Journey Step 1

User's Journey Step 2

User's Journey Step 3

User's Journey Step 4

User's Journey Step 5

User's Journey Step 6

User's Journey Step 7



In above Okta tutorial about OAuth and OPEN ID connect, what has not been mentioned is that there exists some form of trust relationship between the identity provider and the resource server. Perhaps the resource server can directly contact the identity provider to validate the presented code from the client, or the resource server has a verification key to verify the code validity directly.

Bellow is the diagram describes the above statement

image
reboottime commented 1 year ago

OAuth and OPENID Connect (OIDC)

Recap on OAuth

OAuth is designed solely for authorization, allowing one application to grant access to data and features to another application. The OAuth flow provides the client with the necessary keys to access your data but does not reveal any information about the user's identity or characteristics.


OPENID Connect (OIDC)

OIDC is a layer built on top of OAuth 2.0, enhancing it with functionality related to user authentication and profile information. It enables the retrieval of information about the person who is logged in. For example, sign-in functionality using Google authentication.

OIDC with Google Authentication


Single Sign-On (SSO)

SSO, or "Single Sign-On," is an authentication process that allows users to access multiple applications or services using a single set of credentials, such as a username and password. Instead of needing separate login credentials for each application or service, SSO enables you to use the same login credentials for Google Mail and Google Docs, for instance.

Single Sign-On (SSO)


OIDC vs OAuth

OIDC vs OAuth
OIDC vs OAuth
OIDC vs OAuth

The ID token used in OIDC is similar to a JWT token, allowing you to decode encoded information or verify its integrity.

reboottime commented 1 year ago

References