Authentication & Permissions

Authenticated is not authorized: 401 vs 403, capabilities per route and per object, and how much data comes back.

4 lessons16 interview questions

Three reviews. Three questions. wordpress.org review sent our plugins back three times for REST permissions: once for who may call a route, once for which object, once for how much came back. This module turns those reviews into a checklist.

CourseWordPress REST API Course ยท Module 4 of 9 ยท Stage 2 "Build your own"
LearnCookie + nonce, Application Passwords, permission_callback with capabilities, object-level checks, response scope
HowThree real review rounds (4WP Drive, 4WP TODO), the fixes that passed, interview questions after every lesson

Three questions before every route

flowchart LR
  A["Who may call it?<br/>401 ยท guest"] --> B["Which object?<br/>403 ยท edit_post on post_id"]
  B --> C["How much comes back?<br/>only what the user may see"]
  classDef q fill:#feebeb,stroke:#f93e3e,color:#1e293b
  class A,B,C q

Authenticated is not authorized. Check the user, then the object, then the response.

Before โ†’ after

BeforeAfter Module 4
Global edit_posts on every routecapabilities from the post type of the import
Access to the plugin = access to any post_idedit_post on the target object
A list of all users in the responseonly data the user can already see
401 and 403 treated the same401 not logged in ยท 403 logged in, not allowed

You'll be able to answer

  • What is the difference between 401 and 403 in WordPress REST?
  • How do you check permissions for a specific object in permission_callback?
  • How does an external script authenticate to the WordPress REST API?

Lessons in this module 4 lessons