PHP code example of cakedc / cakephp-oauth-server

1. Go to this page and download the library: Download cakedc/cakephp-oauth-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cakedc / cakephp-oauth-server example snippets


   public function bootstrap(): void
   {
       parent::bootstrap();
       $this->addPlugin('CakeDC/OAuthServer');
   }
   

   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'],
               ],
           ],
       ],
   ];
   

   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);