An API request can have the correct URL, method and payload, yet still fail before it reaches the data you need. The reason is often authentication. A missing token, an incorrectly formatted header or an expired API key can turn an otherwise valid request into a 401 Unauthorized or 403 Forbidden response.
If you work with APIs, you will regularly come across API keys, Bearer tokens and OAuth 2.0. They all help control access, but they do not work in exactly the same way. Choosing the right method depends on who or what is making the request, how sensitive the data is and how access needs to be managed.
Let’s look at how each authentication method works, when to use it and how to test it with an API client such as HTTPBot.
What is API authentication?
API authentication is the process of verifying the identity or credentials presented by a client before allowing access to an API.
When an application sends a request to a protected endpoint, it needs to provide valid authentication credentials. The API checks those credentials and decides whether the request can proceed.
Three common approaches are:
- API keys: A unique value supplied with a request to identify or authorise an application.
- Bearer tokens: Access tokens sent in an HTTP Authorization header. Anyone holding a valid token can generally use it, subject to its permissions and expiry.
- OAuth 2.0: An authorisation framework that allows applications to obtain limited access tokens without sharing a user’s password with the client application.
An important distinction: Bearer is a token authentication scheme, not an alternative authorisation framework to OAuth 2.0. OAuth 2.0 commonly issues access tokens that are then sent using the Bearer scheme.
1. API keys: Simple authentication for application access
An API key is a unique string that an API provider issues to identify a client or application. It is commonly used for server-to-server communication, developer services and APIs where access is tied to a particular project or account.
An API key may be sent in a request header:
GET https://api.example.com/products
X-API-Key: your_api_key
Some APIs accept keys through query parameters, although headers are generally preferable because URLs can appear in logs, browser history and other places where credentials should not be exposed.
When should you use API keys?
API keys are a practical choice when:
- A backend service needs to access another service.
- You are integrating with a third-party API.
- Access is associated with an application or project rather than an individual user.
- The API provider offers key-based access with suitable restrictions.
What should you test?
When testing API key authentication, try the following:
- Send a request with a valid API key and confirm the expected response.
- Remove the key and check whether the API rejects the request.
- Send an incorrect or revoked key.
- Check whether the key has the expected access restrictions.
- Verify that the API does not expose the key in its response or error messages.
Remember that an API key is a credential, not a security measure on its own. Use HTTPS, restrict keys where possible, rotate them when necessary and avoid embedding sensitive keys in public client-side applications.
2. Bearer tokens: Access using a token
Bearer authentication works by sending an access token in the HTTP Authorization header.
The format is straightforward:
GET https://api.example.com/profile
Authorization: Bearer your_access_token
The API validates the token before allowing access. Depending on the system, the token may contain or reference information about the authorised user, application, permissions and expiry.
Bearer tokens are often used with OAuth 2.0, but they can also be issued through other authentication systems. The key point is that the client presents the token to prove it has access.
When should you use Bearer token authentication?
Bearer tokens are useful when:
- An application needs to access a protected API.
- A service issues short-lived access tokens.
- Requests need to carry permissions associated with a user or application.
- You are testing an API that expects a token issued by an existing authentication system.
What should you test?
A valid token is only one part of the test. Check how the API behaves in different situations:
- Valid token: Does the request return the expected data?
- Missing token: Does the API reject the request?
- Expired token: Does it return an appropriate authentication error?
- Invalid token: Is access denied?
- Insufficient permissions: Does the API prevent access to restricted resources?
Also check the exact header format. A token sent without the Bearer prefix may be rejected even if the token itself is valid.
Keep in mind that anyone who obtains a valid Bearer token may be able to use it. Store tokens carefully, avoid sharing them in screenshots or logs and use short expiry periods where appropriate.
3. OAuth 2.0: Delegated access with more control
OAuth 2.0 is an authorisation framework that allows an application to access resources on behalf of a user or as an application itself, depending on the flow.
Instead of asking users to share their passwords with a third-party application, OAuth 2.0 uses an authorisation server to issue access tokens.
A typical flow involves:
- The application requests authorisation.
- The user or application completes the required authentication and consent steps.
- The authorisation server issues an access token.
- The application sends the token to the API.
- The API validates the token and checks the permissions.
OAuth 2.0 supports different grant types for different situations.
| OAuth 2.0 flow | Common use |
| Authorization Code with PKCE | User-facing mobile and web applications |
| Client Credentials | Server-to-server communication |
| Device Authorization | Devices with limited input capabilities |
| Refresh Token | Obtaining a new access token when permitted |
The older Implicit and Resource Owner Password Credentials grants are generally discouraged for modern implementations. Follow current OAuth security guidance and the requirements of the API provider.
When should you use OAuth 2.0?
OAuth 2.0 is a good fit when an application needs delegated access, scoped permissions, token expiry and refresh, or a structured authorisation process involving users.
What should you test?
OAuth testing involves more than checking whether a token works.
- Confirm that the correct authorisation endpoint is used.
- Check the client ID and redirect URI.
- Verify the requested scopes.
- Confirm that the access token is issued successfully.
- Test the access token against the protected API.
- Check token expiry and refresh behaviour.
- Verify that requests with insufficient scopes are rejected.
For mobile applications, Authorization Code with PKCE is commonly recommended because it protects the authorisation code exchange without requiring a client secret to be embedded in the app.
Bearer vs OAuth 2.0 vs API keys: Which should you choose?
The right choice depends on the API’s security requirements and how the client accesses it.
| Factor | API keys | Bearer tokens | OAuth 2.0 |
| Main purpose | Identify or authorise an application | Present an access token | Manage delegated or application authorisation |
| Typical use | API integrations | Protected API requests | User or service authorisation |
| Expiry | Depends on provider | Often time-limited | Depends on token and provider policy |
| Permissions | Often configured against the key | Determined by token or server policy | Can use scopes and other access controls |
| Setup | Usually simple | Requires a valid token | Requires an authorisation flow or token setup |
For a simple integration, an API key may be enough. If an API expects a token, use its documented Bearer format. If an application needs delegated access and more structured permission management, OAuth 2.0 is often the better fit.
Always follow the API provider’s authentication documentation rather than choosing a method based only on convenience.
How to test API authentication using HTTPBot
Once you understand the authentication method, the next step is to test it against the actual endpoint.
HTTPBot is a native API client for iPhone, iPad and Mac that lets you build HTTP requests, configure authentication and inspect responses.
A practical testing workflow looks like this:
- Create a request: Enter the API endpoint and select the required HTTP method.
- Configure authentication: Add the API key or Bearer token in the appropriate authentication settings or request header. For OAuth 2.0, configure the required flow and authorisation details.
- Send the request: Check the response status, headers and body.
- Test failure cases: Try missing, invalid or expired credentials where you can safely do so.
- Save the request: Organise frequently used requests into collections so you can repeat tests without rebuilding them.
HTTPBot supports OAuth 2.0 and other authentication methods, and its request editor lets you inspect headers and responses. You can also organise requests into collections and use environments to manage values across different setups.
If you already have a cURL command containing authentication headers, our guide on converting a cURL command to an HTTP request explains how to bring that request into a visual API client.
Common API authentication testing mistakes
A few small mistakes can make authentication tests misleading or leave credentials exposed.
- Testing only valid credentials: Always check how the API handles missing, invalid and expired credentials.
- Using the wrong header format: Authorization: Bearer token is not the same as sending the token alone.
- Ignoring token expiry: A request that works today may fail when its access token expires.
- Requesting excessive permissions: Ask only for the scopes the application actually needs.
- Sharing credentials in logs: Mask API keys, access tokens and client secrets in screenshots, logs and shared collections.
- Using production credentials for experiments: Prefer development or staging credentials when testing failure scenarios.
Good authentication testing checks both successful access and the boundaries that prevent unauthorised access.
Conclusion
API keys, Bearer tokens and OAuth 2.0 solve related but different authentication problems. API keys offer a straightforward way to identify applications, Bearer tokens let clients present access credentials, and OAuth 2.0 provides a framework for managing delegated or application access.
Knowing the difference helps you choose the right approach and troubleshoot authentication failures faster. More importantly, testing both valid and invalid credentials helps confirm that your API is protecting the resources it should.
Whether you are checking a simple API key integration or debugging an OAuth 2.0 flow, HTTPBot gives you a convenient way to build requests, configure authentication and inspect responses across your Apple devices.
Download HTTPBot from the App Store and test your API authentication flows from your iPhone, iPad or Mac.
