oauth2-server-php icon indicating copy to clipboard operation
oauth2-server-php copied to clipboard

Revoking token

Open cgkronos opened this issue 3 years ago • 0 comments

I'm trying to revoke a token in php using this lib but I keep getting a false after calling handleRevokeRequest I'm struggling to find working example on the web

public function revokeToken($token, $sendError = true, $method = null)
    {
        require_once dirname(__FILE__) . '/vendor/autoload.php';
        require_once dirname(__FILE__) . '/OAuthStorage.class.php';
        OAuth2\Autoloader::register();

        $storage = new OAuth2\Storage\OvidentiaOAuthStorage();
        $server = new OAuth2\Server($storage);

        // Add the 'Authorization Code' grant type (this is where the oauth magic happens)


        $server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage));

        if ($method == null) {
            $method = $_SERVER['REQUEST_METHOD'];
        }

        $request = new OAuth2\Request(array(), array('token' => $token), array(), array(), array(), array('REQUEST_METHOD' => $method));


        if (!$server->handleRevokeRequest($request)) {
            if ($sendError === true) {
                $server->getResponse()->send();                
                die;
            } else {
                $this->errorMessages = array();
                $error = $server->getResponse()->getParameters();
                if (isset($error['error_description'])) {
                    var_dump($error['error_description']);
                    $this->errorMessages[] = $error['error_description'];
                }
                return false;
            }
        } else {
            var_dump("else");
        }

        return true;
    }

cgkronos avatar Sep 12 '22 20:09 cgkronos