client credentials grant - RTLer/laravel-oauth2-server GitHub Wiki
first add a client into oauth_clients table, with this datas:
'_id' => 'foo',
'grant_type' => 'client_credentials',\\ optional, it fix it to just work with password credentials grant
'secret' => 'bar',
'name' => 'foo_client',
'redirect_uri' => 'http://foo/bar',
'scopes' => json_encode(['scopeOne', 'scopeTwo']), \\ optional, set array here instead of json_encode for usage with mongo
then make route like getAccessToken and add this into it
<?php
namespace App\Http\Controllers;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use RTLer\Oauth2\Facade\Oauth2Server;
class OAuthController extends Controller
{
public function postAccessToken(ServerRequestInterface $request, ResponseInterface $response)
{
// ['client_credentials'] shows which grant is active
$response = Oauth2Server::makeAuthorizationServer(['client_credentials'])
->respondToAccessTokenRequest($request, $response);
return $response;
}
}
see Flow for usage info