An Interview question every developer should know. What's the...

@RaulJuncoV
Raul Junco@RaulJuncoV
48 views Sep 01, 2024 ~1 min read
Advertisement
1
An Interview question every developer should know.

What's the difference between Tokens and API keys?

We use API keys and tokens for authentication and authorization.

But they serve different purposes and have distinct characteristics.

Tokens (like JWT - JSON Web Tokens):

Carries user context and permissions for authentication and authorization.

Encoded with a user ID, permissions, and expiration time, often in JWT format.

Critical for user-specific access, like accessing a user's profile data in an e-commerce platform.

It is issued by an authentication server after user login and contains user-specific information.

API Key:

Primarily for identifying the application or the consumer making the API call.

They are long strings we pass in the header or as a query parameter in the API request.

You use API keys when access does not involve user context. For example, accessing a public API or service-to-service communication.

They are long-lived and created through the API provider's platform or admin console.

In simple terms:

- Tokens are for managing user sessions, permissions, and context.

- API keys are for identifying applications.

Which one have you used the most?
Media image
2
Are you into system design?

Subscribe to my weekly newsletter for more. 👇

systemdesignclassroom.substack.com
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement