Authentication establishes who or what is calling; it does not decide what that principal may do. Prefer a mature identity provider and standards-based validation over inventing login protocols. Whether using secure server sessions or short-lived tokens, validate issuer, audience, signature, time claims, lifecycle, and transport before constructing a trusted principal.
For a same-origin browser application, an opaque server-side session in a Secure, HttpOnly, appropriately SameSite cookie often reduces token exposure to JavaScript. Add CSRF protection for state-changing requests. For distributed API clients, short-lived OAuth access tokens may be appropriate. Do not place tokens in URLs or browser local storage without a threat-informed reason.
Decoding base64 is not validation. Cache provider keys with bounded TTL and handle key rotation. Never accept an algorithm supplied by the token as unrestricted policy.
Represent the result as an application-owned principal:
Tenant memberships and permissions come from your authoritative data, not arbitrary token roles unless governance explicitly makes the issuer authoritative for them.
Use a maintained library implementing a current adaptive password hash such as Argon2id, unique salts, safe parameters, login throttling, breached-password policy, MFA options, secure reset tokens, and hash upgrades on successful login. Never encrypt passwords for later recovery.
AI tools must execute as a constrained principal with delegated, auditable authority. A model cannot invent a user, tenant, or scope. Service-to-service calls should use workload identity and short-lived credentials where possible, not one shared API key copied across environments.
Design authentication for a same-origin web app, CLI, and background worker. Include credential storage, validation, refresh, logout/revocation, CSRF, and audit events.
Acceptance criteria: stolen credentials have a bounded lifetime, each client uses an appropriate flow, and tests reject wrong issuer, audience, signature, expiry, and replay policy.