An OAuth 2.1 authorization server for CakePHP 5 applications. It lets AI assistants (claude.ai, Claude Code, other MCP clients) and your own programs get access tokens for your application's people. People sign in with the login your application already has, approve what a client may do on a consent page, and review or revoke their connections on a connections page.
The plugin is a thin CakePHP layer on top of cakedc/oauth-server,
the framework independent core. The core does the OAuth work (endpoints, PKCE, refresh token rotation,
Client ID Metadata Documents, dynamic registration, rate limits). The plugin adds what a Cake application
needs: ORM storage and a migration, routes, an authenticator for cakephp/authentication, Cake views for
the pages, console commands, events on Cake's event manager and a test trait. The OAuth concepts, the
endpoint reference, the security model and the client setup guides live in the core's documentation, and
this documentation links to them instead of repeating them.
- PHP 8.2 or later
- CakePHP 5.1.10 or later
cakephp/authentication3.3.6 or later (your application needs a login that sets theidentityrequest attribute)cakephp/migrations4 or 5- Optional:
cakedc/usersfor a ready-made login (see cakedc-users),cakedc/authfor RBAC rules,cakephp/authorization
The floors are the oldest releases without known security advisories, which are also the oldest that current
Composer installs: CakePHP before 5.1.10 and cakephp/authentication before 3.3.6 have published advisories,
one of them an open redirect in the login return flow (?redirect=), the very flow the consent page sends people
through.
-
Install the plugin and the core. Both are betas: Composer reads stability flags only from your application's
composer.json, so name both (or set"minimum-stability": "beta"with"prefer-stable": true, see installation).composer require cakedc/cakephp-oauth-server:^1.0@beta cakedc/oauth-server:^1.0@beta
-
Load it in
src/Application.php.public function bootstrap(): void { parent::bootstrap(); $this->addPlugin('CakeDC/OAuthServer'); }
-
Create the tables.
bin/cake migrations migrate -p CakeDC/OAuthServer
-
Declare the resource you protect, in
config/app_local.php(one resource is enough to start). The issuer defaults toApp.fullBaseUrland the secret is derived fromSecurity.salt.return [ 'OAuthServer' => [ 'resources' => [ 'https://example.com/mcp' => [ 'name' => 'Example MCP', 'scopes' => [ 'content:read' => 'Read your posts', 'content:write' => 'Edit drafts', ], 'implies' => ['content:write' => ['content:read']], 'defaultScopes' => ['content:read'], ], ], ], ];
-
Let OAuth clients call the token endpoints, and API and MCP clients call your resources' routes, without a CSRF token (on those routes a request is skipped when it carries a bearer token of this server, or no credential at all; the CSRF cookie does not count, see installation). In
Application::middleware(), afterRoutingMiddleware, with the Token authenticator loaded before the session one:use CakeDC\OAuthServer\OAuthServer; use Cake\Http\Middleware\CsrfProtectionMiddleware; use Psr\Http\Message\ServerRequestInterface; $csrf = new CsrfProtectionMiddleware(); $csrf->skipCheckCallback(fn (ServerRequestInterface $request): bool => OAuthServer::csrfSkip($request)); $middlewareQueue->add($csrf);
-
Check the setup.
bin/cake oauth check
No line may say
FAIL. AWARNis a hint (for example, that the secret is derived fromSecurity.salt). -
Connect a client. The metadata document is at
https://example.com/.well-known/oauth-authorization-server. To connect Claude, follow clients in the core documentation. Protect your MCP endpoint or API as described in protecting-apis and mcp.
The consent page needs a person who is signed in. If your application has no login yet, read installation first.
- Contents
- Installation: Composer, loading, migrations, CSRF, routes, authentication
- Configuration: every key, with defaults
- Users: who may sign in, who may authorize, service identities
- cakedc/users: the plug and play integration
- Protecting APIs: the token authenticator and scope checks
- Pages: consent and connections pages, layouts, templates, translations
- Commands: the
oauthconsole commands - Events: the six events and an audit log listener
- Testing:
OAuthTestTrait - MCP: protecting a
cakedc/cakephp-mcpserver - Deployment: https, proxies, subdirectories, nginx
- Security: what the plugin adds and a production checklist
- Troubleshooting
Not a CakePHP application? Use the core package cakedc/oauth-server directly.
MIT. See LICENSE.