Understanding Authentication vs Authorization

1. Defining Authentication

Authentication (AuthN) verifies who a principal claims to be by validating credentials against a trusted identity store.

AspectDescriptionExample
PurposeIdentity verificationLogin, SSO
QuestionWho are you?Username + password
OutputAuthenticated principalUser object, JWT subject
FactorsKnowledge / Possession / InherencePassword / Token / Biometric
Failure Code401 UnauthorizedMissing/invalid credentials

2. Defining Authorization

Authorization (AuthZ) determines what an authenticated principal can do based on policies, roles, or attributes.

AspectDescriptionExample
PurposePermission evaluationRBAC, ABAC, ACL
QuestionWhat can you do?Can user.read?
InputPrincipal + Resource + Action(alice, /orders/42, DELETE)
ModelsRBAC, ABAC, ReBAC, PBACRoles, attributes, relationships
Failure Code403 ForbiddenAuthenticated but denied

3. Understanding Authentication Flow

Client → [Credentials] → Auth Service → Identity Store
                              ↓
                       Verify + Issue Token
                              ↓
Client ← [Session/Token] ← Auth Service
      
StepActionArtifact
1Submit credentialsPOST /login
2Lookup userDB / LDAP query
3Verify secretbcrypt compare
4Issue session/tokenCookie / JWT
5Subsequent requestsBearer / Cookie

4. Understanding Authorization Flow

Request + Token → PEP (Policy Enforcement Point)
                       ↓
                 PDP (Policy Decision Point)
                  ↙        ↓        ↘
            PIP (info)  Policy   Context
                       ↓
                  Permit / Deny
      
ComponentRole
PEPIntercepts request, enforces decision
PDPEvaluates policies against request
PIPProvides attributes (user, resource)
PAPPolicy Administration Point (manage policies)

5. Understanding Principal and Subject Concepts

TermDefinitionExample
PrincipalEntity making the requestUser, service, device
SubjectAuthenticated principal identifiersub claim in JWT
IdentitySet of attributes describing principalusername, email, roles
ActorService acting on behalf of subjectOAuth on-behalf-of

6. Understanding Credentials and Claims

TypeDescriptionExample
CredentialSecret proving identityPassword, private key, OTP
ClaimAssertion about a subject"role":"admin"
Standard ClaimsJWT/OIDC definediss, sub, aud, exp, iat
Custom ClaimsApp-specific"tenant":"acme"

7. Understanding Trust Boundaries

A trust boundary is the perimeter at which data validation, authentication, and authorization decisions must occur. Crossing a boundary requires re-verification.

BoundaryControl
Client ↔ APITLS + token validation
Service ↔ ServicemTLS + service tokens
App ↔ DatabaseConnection auth + least privilege
Tenant ↔ TenantRow-level security + claim check

8. Combining Authentication and Authorization

Example: Express middleware chain

// AuthN then AuthZ
app.get("/admin/users",
  authenticate,                        // verifies JWT, sets req.user
  authorize(["admin", "superadmin"]),  // checks roles
  (req, res) => res.json(users)
);

function authenticate(req, res, next) {
  const token = req.headers.authorization?.replace("Bearer ", "");
  try { req.user = jwt.verify(token, PUBLIC_KEY); next(); }
  catch { res.status(401).json({ error: "invalid_token" }); }
}

function authorize(roles) {
  return (req, res, next) => roles.includes(req.user.role)
    ? next() : res.status(403).json({ error: "forbidden" });
}

9. Understanding Defense in Depth

LayerControl
NetworkWAF, DDoS protection, IP allowlists
TransportTLS 1.3, HSTS, certificate pinning
ApplicationAuthN, AuthZ, CSRF, input validation
DataEncryption at rest, field-level encryption
MonitoringAudit logs, SIEM, anomaly detection

10. Understanding Zero Trust Model

PrincipleImplementation
Never trust, always verifyAuthenticate every request
Least privilegeMinimal scopes per token
Assume breachMicro-segmentation, short-lived tokens
Verify explicitlyDevice + user + context signals
Continuous validationRe-auth on risk change
Note: Perimeter-based trust ("inside the network") is obsolete in cloud and remote-work environments.