API Authentication 00:00:01 From password to an authenticated call A signed-in customer closes the shopping app. An hour later a different server receives the next request. How can that server establish who is calling, and how does the answer change after the customer signs out? The user types an email and password in the app. The server reads the user record. Only a slow hash of the password is stored. The record comes back and the hashes match. An unknown user does the same work, so timing gives nothing away. The app receives an access token for 15 minutes and a refresh token for 7 days, and stores them in secure storage. The app sends the access token in the Authorization header. The orders of user_123 go back. The ID came from the token, not from the request body. A client sends credentials over a protected connection to the legitimate identity service. Later requests carry a session reference or token; avoid teaching downstream services to handle the user's password again. 00:01:02 Delegate a sign-in safely OAuth 2.0 code flow with PKCE, plus OpenID Connect for login. The user chooses to continue with Google. The browser goes to the auth server. The user logs in there and agrees to share name and email. ShopEasy never sees the password. The auth server sends the browser back with a short-lived code. Server to server, ShopEasy sends the code, the verifier and its client secret. The auth server returns an access token and an ID token. ShopEasy creates its own session. The browser gets a cookie and no Google token. In a standard sign-in flow, distinguish knowing who the user is from obtaining permission to call a service on the user's behalf. The intended issuer, client and redirect boundary matter. 00:01:50 An application key represents an application A partner's server identifies itself with a key. The partner's server calls the gateway with the key in a header, over HTTPS. The gateway hashes the key and looks for that hash. A leaked table holds no usable keys. The record is active and today's count is below its limit. The count is raised in one atomic step. Products receives the request with the verified app name. Someone turns the key off. The next call gets 401 at the gateway, and Products never sees it. Scope a service credential narrowly, rotate it under a plan and store it outside client-distributed code. A key assigned to an integration is not proof of which human initiated a particular action. 00:02:35 Validate the relevant claims What the orders service checks before it believes a token. The header says HS256, and that is the only one this service accepts. The service computes the signature again and compares in constant time. The token was issued by the expected auth service. It ends at 12:15 and it is 12:04, so it is still valid. All five checks passed. The caller is the sub claim. This one is genuine but made for the cart service. It is refused. Verify the signature with an allowed algorithm and trusted key, then check issuer, audience, expiry and other required constraints. Reading a token's fields alone establishes none of those claims. 00:03:20 Sign-out has a clock The refresh token is deleted. No new access token can be made. Someone kept a copy of the access token. Its signature and dates are fine, so it still works. The token expires and cannot be renewed. Exposure was 11 minutes after the logout. Removing a browser-side copy does not recall every credential already presented elsewhere. Choose lifetime and revocation behavior appropriate to how quickly this application promises access should stop. 00:03:46 Rotate without interrupting good sessions The new public key K2 is published. Everyone still signs with K1. After verifiers have refreshed their copy, the issuer signs with K2. Old tokens still verify with K1. When the last K1 token has expired, K1 is removed. Publish overlapping verification material for legitimate old and new credentials during a controlled rotation. A compromised key is a different event and may require a faster invalidation path. Identify the evidence a service validates, trace who issued it, and define how long that evidence remains acceptable. Authentication is a continuing trust contract, not just the first password form.