API Keys, Sessions, and Service Credentials Explained

Compare API keys, browser sessions, and service credentials, then choose storage, rotation, and transport practices that fit each API client.

published: reading time: 6 min read author: Geek Workbench updated: November 4, 2026
Quick Summary

Choose credentials by caller: browser sessions for people, user-owned keys where an API supports them, and separate identities for services. This guide shows where each credential belongs, why identity checks and authorization are separate, and how to rotate a secret with a measured overlap, detect remaining use, and recover safely when cutover fails.

API Keys, Sessions, and Service Credentials Explained

Introduction

A credential’s meaning depends on who is calling and where the client runs. Browser sessions represent signed-in people. Personal API keys are bearer secrets the API associates with individual users, while service credentials identify workloads. API-key behavior is service-specific. Validating a credential identifies the caller; a separate authorization check decides whether that caller may access the requested resource.

For delegated user identity, read OAuth and OpenID Connect.

Choose a credential for the client

Caller and client Credential to prefer Where it belongs and what it means
Person using a browser app Server-managed session cookie; use an OAuth/OIDC flow when the app needs delegated access to another API The server maps the opaque cookie to a user session. Set Secure, HttpOnly, and an appropriate SameSite value, defend state-changing requests against CSRF, and renew the session ID after login or a privilege change. See the OWASP session guidance.
Person using a CLI or personal script A short-lived delegated token where available; otherwise a personal API key if the API provides one Keep the user-owned bearer credential in an OS credential store or an approved secret manager, never in source code or browser JavaScript. The service defines the key’s exact permissions, so grant only the access that user needs and revoke it when their access changes.
Backend service or scheduled job Platform workload identity or a short-lived service token Bind identity to the workload and authorize its specific operations. If a static secret is unavoidable, issue one per workload and keep it in a secret manager. Do not reuse an employee’s personal API key.
Partner integration A dedicated integration key or machine identity Identify and rate-limit the integration separately from a person. The key can establish which integration sent the request; it does not replace authorization checks on individual resources.

Whichever credential you choose, authorize each requested action and object after identifying the caller. Authentication vs. Authorization explains the distinction; Scopes, Roles, and Object-Level Permissions applies it to resources.

Treat browser code as public: users can inspect files delivered to their browser, so a bundled client secret is not confidential. For OAuth public clients, RFC 9700 requires PKCE. If the app has a backend, keep its OAuth client credentials there rather than sending them to the browser.

Validate identity, then authorize

flowchart TD
  A[Client presents credential] --> B[Validate credential, expiry, and status]
  B --> C[Resolve caller identity and scope]
  C --> D[Authorize requested action and resource]
  D -->|Allowed| E[Process request]
  D -->|Denied| F[Return safe error]
  E --> G[Record outcome without secrets]

Rotate a credential without locking out callers

For a planned rotation, keep the two credentials distinguishable by non-secret IDs. Never put key values in logs, metrics, or example output. A dual-credential overlap only works if the issuer and verifier can accept both values at once; if they cannot, follow that provider’s coordinated replacement procedure instead of assuming overlap is supported. OWASP recommends automating rotation where practical and describes gradual and rapid strategies in its Secrets Management Cheat Sheet.

  1. Inventory each caller, owner, credential ID, scope, and renewal path. Issue the replacement with no broader access than the old credential. If the system supports overlap, set an owner and a firm end date for it.
  2. Put the new value in the caller’s approved secret store and deploy it to a small set of callers. Confirm they can authenticate and complete an authorized operation. Do not print the value during deployment.
  3. Record successful and rejected use by credential ID, not secret value. Move remaining callers, including infrequent jobs. Choose an observation period that covers their actual schedules and retry behavior; there is no universal safe duration.
  4. Disable the old credential after its legitimate traffic has stopped. Check that old-ID requests fail and expected callers continue to work, then remove the old value from deployment stores.
  5. If the new credential fails, pause the rollout and keep the old one only if it remains safe and has not been exposed. Fix the issuance or delivery problem, test the replacement again, and set an approved deadline before extending overlap. If compromise is suspected, revoke the exposed value promptly and use the incident process. Do not keep it active as a rollback path.

For browser sessions, renew the session identifier after authentication or a privilege change, then invalidate the prior identifier. OWASP describes this lifecycle in its session guidance. Cookie sessions rotate identifiers; API credential rotation replaces or renews a secret or token.

Quick recap

  • Match the credential to the caller: browser user, individual user, workload, or partner integration.
  • Validate identity first, then authorize the requested resource.
  • Rotate with a measured overlap when supported; revoke promptly after compromise.

Interview questions

1. How does an API key differ from a user access token?
An API key's meaning is set by the service: it may be associated with a user, project, or integration. An OAuth access token represents delegated access for a resource server and scopes. In either case, the API still needs to authorize the requested resource.
2. Why give each workload its own service credential?
Separate credentials limit access to each workload's needs and make usage attributable. If one is compromised, it can be revoked without disrupting unrelated services.
3. How can a planned credential rotation avoid downtime?
Issue a replacement before revoking the old one when the system supports overlap, migrate callers, and monitor old-key use by non-secret ID. Revoke the old value after all legitimate use has stopped.
4. What should a team do when a credential may be compromised?
Contain the exposure by revoking or disabling the credential promptly, assess affected access, and issue a replacement through the incident process. Do not wait for the ordinary rotation window if the secret is actively at risk.

Further reading

Conclusion

Document an owner, scope, renewal path, and revocation path for every credential. Continue with OAuth and OpenID Connect for delegated user access, then review authorization and object-level permissions to decide what each validated caller may do.

Category

Related Posts

GraphQL Subscriptions: Transports, Security, and Scaling

Choose GraphQL subscription transports, plan authorization and reconnects, and scale event delivery across servers with security and deployment checks.

#graphql #subscriptions #websockets

Secure Design and Session Management

Learn to design safer web sessions with secure cookie flags, identifier rotation, sensible timeouts, revocation, and defenses against CSRF and session abuse.

#cybersecurity #sessions #cookies

CSRF, CORS, and SSRF: Defending Web Request Boundaries

Learn how CSRF, CORS, and SSRF differ, then apply cookie, origin, allowlist, and egress controls to protect browser and server request boundaries.

#web-security #csrf #cors