Authentication vs Authorization: Differences and Examples

Applies to Web applications, APIs, IAM systems, and any service that controls who can sign in and what they may do afterward
Scope Authentication versus authorization definitions, comparison table, login and API request flow, common methods, RBAC and ABAC examples, OAuth versus OpenID Connect roles, and HTTP 401 versus 403 — not a full OAuth/OIDC tutorial or Keycloak install walkthrough
Related guides What is Keycloak?
Install Keycloak with Podman
Short on time?Beta Get the gist of this 10-minute read in seconds, then ask follow-up questions

Authentication and authorization answer two different questions. Authentication asks, "Can you prove who you claim to be?" Authorization asks, "Are you allowed to perform this action?"

For example, signing in with a password is authentication. Being allowed to open the admin dashboard after signing in is authorization. Signing in successfully does not automatically give you permission to do everything.


Authentication vs Authorization: Quick Answer

Question Term What it does
Can you prove you are the account or client you claim to be? Authentication (AuthN) Verify control of an authenticator such as a password, security key, registered phone or authenticator device, or client certificate
Are you allowed to do this action on this resource? Authorization (AuthZ) Check roles, scopes, policies, or rules before granting access

Authentication normally happens before authorization in a protected application, but authorization is not a one-time gate only at login. APIs typically validate the request's credentials or access token and make an authorization decision for each protected request. A service account or API client authenticates too — not only human users.

For broader IAM vocabulary, see What is IAM?.


Authentication: Proving Who You Are

Authentication checks whether a user or system can prove that it controls the account it claims to be using — for example, with a password, security key, or certificate.

Authentication can use one or more authenticators, for example:

  • Password or PIN — something the user knows
  • Registered phone or authenticator device, security key, or smart card — something the user has
  • Client certificate with its private key — commonly used for machine-to-machine authentication such as mutual TLS (mTLS)
  • Client secret — a confidential credential used by some OAuth clients. The client ID identifies the client, while the client secret must be kept confidential.

In OAuth, a client is an application or service requesting access — not the human user or their computer.

Multi-factor authentication (MFA) combines authenticators from more than one factor category — for example, a password plus a registered security key.

Once authentication succeeds, a system may create a login session or issue credentials or tokens that allow subsequent requests to be associated with that authenticated account.

Authentication itself does not decide which files, APIs, or admin pages the account may access.

Showing an ID badge at a controlled entrance is a useful analogy for authentication: you provide evidence for the identity you claim. Whether that badge lets you enter a server room is a separate authorization decision.


Authorization: Deciding What You Can Do

Authorization evaluates whether an authenticated identity may perform a requested action on a requested resource.

Authorization often uses:

  • Roles — named labels such as developer, billing-admin, or viewer
  • Permissions — specific actions such as reading a report or deleting a user
  • OAuth scopes — labels such as reports:read that describe the type of access an application requests or has been granted
  • Policy rules — contextual decisions based on attributes such as department, resource owner, or time of day

Role-based access control (RBAC) maps identities to roles and roles to permissions. Attribute-based access control (ABAC) makes authorization decisions from attributes of the subject, resource, requested action, and environment.

Successful authentication does not imply full access. Priya may sign in correctly and still be denied one admin API because her role allows read but not delete.

Applications, API gateways, and authorization services enforce these checks. Keycloak can include roles, scopes, and other claims in access tokens, but something in the request path still decides whether the operation is allowed. See Keycloak realm roles vs client roles for how role claims reach tokens.


Authentication vs Authorization: Key Differences

Authentication Authorization
Question Who is calling? What may they do?
Typical inputs Account or client identifier plus password, security key, certificate, client secret, or another authenticator Roles, scopes, resource ID, HTTP method, policy attributes
When it runs During login or when a request or session credential must be validated Whenever access to a protected operation is evaluated
Failure signal (common) HTTP 401 Unauthorized when the request lacks valid authentication credentials for the target resource HTTP 403 Forbidden when the server refuses the request despite understanding it
Examples Password login, MFA challenge, mTLS client auth RBAC role check, scope check, ABAC policy decision

Passwords, client secrets, and certificates are used for authentication. Role assignments, permissions, and scope checks are authorization. A password proves control of an account; it does not by itself grant admin rights.

The user does not necessarily re-enter credentials for every request. A session cookie, bearer token, client certificate, or other previously established credential may identify or authenticate the request.


How They Work Together in a Login and API Request

A typical web plus API flow separates the two steps clearly.

Browser login

  1. Priya enters username and password — identification and authentication start.
  2. The IAM server verifies her password and any required additional factor. If authentication succeeds, it creates a login session.
  3. The application reads her roles or other access information and checks whether she may open a protected page or perform an action. It may also hide UI options she cannot use, but the server must still enforce access when the request arrives.

API call with a bearer token

  1. Priya's client sends an access token in the Authorization header.
  2. The API validates the access token — for example, checking its signature and claims when the token is a JWT, or using another validation mechanism appropriate to that token type.
  3. If the token is valid, the API evaluates its scopes, roles, other claims, and request context to decide whether the requested operation is allowed.

For a JWT access token, validation commonly includes verifying its signature and checking claims such as issuer, audience, and expiration. Some access tokens are opaque tokens, meaning the API cannot decode useful claims from the token itself. The API cannot validate an opaque token by decoding it like a JWT; it typically checks the token using a mechanism provided by the authorization server.

A valid bearer access token proves that the caller possesses that token, but it does not necessarily prove the identity of a particular human user. An OAuth access token's main purpose is to grant access to a protected API. For example, a machine using the Client Credentials grant can have an access token even though no person signed in.

Use an access token when calling protected APIs. An OpenID Connect ID token describes who signed in; it is not the token you send to routine resource APIs.

text
GET /api/reports/finance HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6...

Once the API accepts the token, it still has to decide whether that token permits this particular operation. The API may also obtain information about Priya from token claims, depending on how the authorization server issued the token. If her role includes reports:read but not the permission required to delete reports, a DELETE on the same resource can still return 403 Forbidden even when the token is valid.


Common Methods and Protocols

The same distinction appears in browser logins, APIs, and machine-to-machine access.

Authentication methods

  • Password and MFA at a login page
  • TLS client certificates for service APIs
  • Machine or client authentication — for example, a client secret or client certificate

Authorization models

  • RBAC with application or realm roles
  • Scope-based access on OAuth access tokens
  • ABAC with policy engines or custom application logic

OAuth and OpenID Connect are often confused here. OAuth 2.0 is primarily an authorization framework for obtaining access to protected resources. Many OAuth flows involve delegated access on behalf of a user, while flows such as Client Credentials let a machine client request access for itself. OpenID Connect adds a standardized authentication layer on top of OAuth 2.0 for user sign-in.

Keycloak can act as an OpenID Connect identity provider and OAuth authorization server. It authenticates users for OIDC login and issues access tokens that APIs can use when making authorization decisions. Keycloak clients explained covers how applications register as OIDC clients or SAML service providers.


Authentication and Authorization Examples

Scenario Authentication Authorization
Priya signs in with password and MFA Password plus OTP prove control of her account Application permits access only to dashboards allowed by her ops-viewer role
CI job calls a deployment API Client secret or client certificate authenticates the CI job API requires an access token granted the deploy:production scope
Priya opens a shared file link anonymously No authentication — guest access Link policy allows read-only view without sign-in
Valid token, wrong operation Valid bearer token presented to the API DELETE denied because the token has reports:read but not the permission required to delete reports

Non-human clients authenticate with credentials or certificates, then authorization still limits which endpoints they may call.


401 vs 403: Where the Difference Appears

Many HTTP APIs use status codes to signal which step failed:

Status HTTP meaning Common API interpretation
401 Unauthorized Request lacks valid authentication credentials for the target resource Missing, expired, malformed, or invalid token
403 Forbidden Server understands the request but refuses to fulfill it Credentials may be valid, but caller lacks sufficient permission

Despite its name, HTTP 401 Unauthorized is normally associated with authentication, while 403 Forbidden is commonly used for an authenticated caller who lacks sufficient access. APIs may deliberately return 404 Not Found instead of 403 when revealing that a resource exists would disclose information.

Example — missing or invalid token:

text
GET /api/reports/finance HTTP/1.1
Host: api.example.com

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer

Example — valid token, insufficient permission:

text
DELETE /api/reports/finance/annual HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6...

HTTP/1.1 403 Forbidden

Summary

Authentication verifies that a user or system can prove control of the account it claims to be using. Authorization decides what that authenticated user or system is allowed to do. Authentication and authorization often work together: first the system verifies the account or caller, then protected resources evaluate whether that caller has sufficient access.

OAuth 2.0 is primarily an authorization framework for obtaining access to protected resources; OpenID Connect adds standardized user sign-in on top. In OAuth-protected API calls, the resource server first validates the access token and then determines whether the token grants sufficient access for the requested operation. When debugging, 401 usually points to missing or invalid credentials, while 403 often means the caller is known but not allowed for that operation.


References


Frequently Asked Questions

Which comes first, authentication or authorization?

In most protected applications, authentication comes first: the system establishes who is calling. Authorization then runs for each protected action or API request. Some resources allow anonymous access, so authorization can occur without prior authentication for those paths only.

Is a password authentication or authorization?

A password is an authenticator in the knowledge-factor category. It is used for authentication, not authorization. A role such as admin is authorization information that the application can evaluate when deciding whether to allow an action.

What is authn vs authz?

AuthN means authentication — proving control of the authenticator associated with the account you claim to be using. AuthZ means authorization — deciding what that account is permitted to access or do. They answer different questions and fail for different reasons.

What is the difference between 401 and 403?

HTTP 401 Unauthorized means the request lacks valid authentication credentials for the target resource; servers generating a 401 response normally include a WWW-Authenticate challenge. HTTP 403 Forbidden means the server understood the request but refuses to fulfill it — the caller may be authenticated but lack permission. Some APIs return 404 instead of 403 to avoid revealing that a protected resource exists.

Is OAuth authentication or authorization?

OAuth 2.0 is primarily an authorization framework for obtaining access to protected resources. OpenID Connect adds authentication on top of OAuth with ID tokens and standardized user identity claims. In practice you often use both together, but they solve different problems.

Finished reading?Beta Get the key takeaways in seconds, then ask follow-up questions
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with 15+ years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.

  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security
  • Cloud Computing
  • Kubernetes
  • Linux
  • Ansible (software)