ThisCalculator

Everyday

WordPress REST API Authentication: How to Choose

Updated · Standard formula, shown below

To choose the right WordPress REST API authentication method for your client, match the method to the client type and security needs: use Application Passwords for most server-to-server or plugin integrations, OAuth 2.0 for third-party apps that need user consent, and JWT for single-page or mobile apps where you control the client code. The wrong choice can expose data or frustrate users, so this guide breaks down each option, when to use it, and common pitfalls.

Background: Why Authentication Matters

WordPress’s REST API lets external apps read and write posts, users, and settings. Without authentication, the API only allows read access to public content. Any write operation, or reading private data, requires proof of identity. The core API supports cookie authentication for logged-in admin screens, but that doesn’t work for external clients like mobile apps or cron jobs. Over the years, the WordPress community developed several standard methods, and in 2020 WordPress core added Application Passwords, making a secure, built-in option available to everyone.

How the Main Methods Work

  • Application Passwords – You create a long random password in the user’s profile, then send it via Basic Auth (base64-encoded) in the Authorization header. Works over HTTPS only. Simple, no extra plugin needed, but the password is as powerful as the user’s actual password.
  • OAuth 2.0 – A standard protocol where a user clicks “Allow” on a screen, and your app receives an access token. Requires an OAuth plugin (like WP OAuth Server). Best for third-party apps that many users will connect to their own sites.
  • JWT (JSON Web Tokens) – A plugin issues a signed token after login. The client sends the token in the header for each request. Tokens can expire or be refreshed. Good for SPAs and mobile apps, but you must handle token storage securely.
  • Cookie Authentication – Uses WordPress’s built-in nonce and cookie system. Only works when the client is a browser on the same site (like an admin page making AJAX calls). Not for external apps.

How to Choose: Decision Factors

Ask these questions before picking a method:

  • Who is the client? – A single site owner’s custom script, or a public app used by thousands of different WordPress sites?
  • Where does the client run? – On a server, in a browser, or on a mobile device?
  • Does the user need to approve access? – If yes, OAuth 2.0 is the standard. If you control the client and the user is the same person, Application Passwords are simpler.
  • Do you need fine-grained permissions? – Application Passwords currently grant the same capabilities as the user. OAuth can be scoped (though WordPress’s implementation often still uses the user’s full role).
  • What’s your hosting environment? – Some shared hosts block Basic Auth headers, which breaks Application Passwords. In that case, JWT or OAuth may be more reliable.

Common Problems and Misconceptions

A frequent mistake is using JWT for a simple server-to-server script when Application Passwords would work with less code. Another is sending passwords or tokens in URL query strings, which get logged by proxies and servers. Always use headers. Also, many developers assume OAuth is always more secure than Application Passwords, but if you store the OAuth client secret on a user’s phone, it’s not much different. The biggest real-world problem is forgetting that all these methods require HTTPS. Without encryption, anyone on the network can read the credentials.

Comparison: Security, Effort, and Use Case

Method Security Setup Effort Best For
Application Passwords High (if HTTPS) Low – built into core Your own scripts, cron jobs, plugin integrations
OAuth 2.0 High Medium – needs plugin and redirect URIs Public apps connecting many users
JWT High (if stored safely) Medium – token refresh logic SPAs, mobile apps, headless WordPress
Cookie Good for browser Low – but limited Admin AJAX, same-origin requests

Costs and Maintenance

Application Passwords are free and built into WordPress core, so no plugin updates to worry about. OAuth and JWT require third-party plugins, which may have free versions but often charge for advanced features like refresh tokens or multi-site support. Even free plugins need updates and can break with WordPress core changes. The real cost is development time: JWT requires you to handle token expiration, refresh, and revocation. OAuth requires setting up callback URLs and managing client secrets. Application Passwords require almost no code – just a header.

Safety and Best Practices

  • Always use HTTPS. Never send credentials over plain HTTP.
  • Store tokens and passwords only in secure environments (server-side, not in client-side JavaScript).
  • Use the smallest privilege: create a dedicated WordPress user with only the capabilities the client needs, rather than an admin.
  • Revoke Application Passwords immediately if you suspect a leak.
  • For JWT, set a short expiry (e.g., 15 minutes) and use a refresh token that is also short-lived and rotated.
  • Never log the Authorization header.

Frequently Asked Questions

Can I use Application Passwords with the WordPress mobile app?

Yes, the official WordPress mobile apps support Application Passwords. You generate one in your profile and enter it as the password when the app asks. It’s a common way to connect apps without sharing your main password.

Is JWT more secure than Application Passwords?

Not inherently. Both are secure when used over HTTPS with proper storage. JWT’s advantage is that it doesn’t send the user’s password on every request, but if the token is stolen, it’s just as dangerous. Application Passwords are simpler and have fewer moving parts, which reduces attack surface.

What if my host blocks Basic Auth headers?

Some shared hosts or CDNs strip Authorization headers. You can test by sending a request and seeing if you get a 401 error. If so, switch to JWT or OAuth, which use different header names (like Authorization: Bearer) and may pass through. Alternatively, contact your host to whitelist the header.

Do I need a plugin for OAuth 2.0?

WordPress core does not include OAuth 2.0 server functionality. You need a plugin like WP OAuth Server or a third-party service. The plugin handles token issuance, refresh, and user consent screens. Choose one that is actively maintained and has good reviews.

Can I use multiple authentication methods at once?

Yes, and it’s common. For example, a site might use Application Passwords for internal cron jobs and OAuth for a public mobile app. WordPress allows multiple methods to coexist as long as they are properly hooked into the REST API authentication filters.

How do I test my authentication without exposing credentials?

Use a local development environment and tools like Postman or curl. Create a test user with limited capabilities. Never use your production admin account for testing. Also, use a test site that doesn’t contain real customer data.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.