Hi there,
I’m trying to put together Slim4 and OAuth2 server (GitHub - bshaffer/oauth2-server-php: A library for implementing an OAuth2 Server in php). But IDE and Slim tell me that could not found \OAuth2\Server class, but it is in the lib folder and accessible.
But when I call my class with method which I need got this message:
Call to undefined function OAuth2\Server()
I think that something with my settings in Slim instance, but can’t understand what, because I’m newbie in Slim4 framework.
class OAuth2
{
/** @var \OAuth2\Server */
private $server;
public function __construct(ContainerInterface $container)
{
$storage = new \OAuth2\Storage\Pdo([
'dsn' => 'mysql:dbname=alice-grms;host=127.0.0.1',
'username' => 'alice_grms',
'password' => 'alice_grms',
]);
$this->server = \OAuth2\Server($storage);
// Add the "Client Credentials" grant type (it is the simplest of the grant types)
$this->server->addGrantType(new ClientCredentials($storage));
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$this->server->addGrantType(new AuthorizationCode($storage));
}
public function token()
{
// Handle a request for an OAuth2.0 Access Token and send the response to the client
$this->server->handleTokenRequest(\OAuth2\Request::createFromGlobals())->send();
}
}