add refresh token grant type

This commit is contained in:
Mike Macgirvin 2022-12-29 19:07:40 +11:00
parent d2771649a8
commit 06b51d1f86
4 changed files with 12 additions and 2 deletions

View file

@ -6,6 +6,7 @@ use Code\Lib\System;
use OAuth2\Server;
use OAuth2\Storage\Memory;
use OAuth2\GrantType\ClientCredentials;
use OAuth2\GrantType\RefreshToken;
use OAuth2\OpenID\GrantType\AuthorizationCode;
class OAuth2Server extends Server
@ -32,7 +33,8 @@ class OAuth2Server extends Server
// Need to use OpenID\GrantType to return id_token
// (see:https://github.com/bshaffer/oauth2-server-php/issues/443)
$this->addGrantType(new AuthorizationCode($storage));
// Add the "Refresh Token" grant type
$this->addGrantType(new RefreshToken($storage));
$keyStorage = new Memory([
'keys' => [
'public_key' => get_config('system', 'pubkey'),

View file

@ -8,6 +8,7 @@ use Code\Lib\Channel;
use Code\Web\Controller;
use Code\Identity\OAuth2Server;
use Code\Identity\OAuth2Storage;
use OAuth2\GrantType\RefreshToken;
use OAuth2\Request;
use OAuth2\Response;
use OAuth2\GrantType;
@ -61,7 +62,8 @@ class Authorize extends Controller
$server->addGrantType(new GrantType\ClientCredentials($storage));
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$server->addGrantType(new GrantType\AuthorizationCode($storage));
// Add the "Refresh Token" grant type
$server->addGrantType(new GrantType\RefreshToken($storage));
// TODO: The automatic client registration protocol below should adhere more
// closely to "OAuth 2.0 Dynamic Client Registration Protocol" defined

View file

@ -44,6 +44,9 @@ class Token extends Controller
$server->addGrantType(new GrantType\ClientCredentials($storage));
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$server->addGrantType(new GrantType\AuthorizationCode($storage));
// Add the "Refresh Token" grant type
$server->addGrantType(new GrantType\RefreshToken($storage));
$request = Request::createFromGlobals();
$response = $server->handleTokenRequest($request);
$response->send();

View file

@ -39,6 +39,9 @@ function api_login()
$server->addGrantType(new GrantType\ClientCredentials($storage));
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$server->addGrantType(new GrantType\AuthorizationCode($storage));
// Add the "Refresh Token" grant type
$server->addGrantType(new GrantType\RefreshToken($storage));
$request = Request::createFromGlobals();
if ($server->verifyResourceRequest($request)) {
$token = $server->getAccessTokenData($request);