mezzio-authentication-oauth2
mezzio-authentication-oauth2 copied to clipboard
AuthenticationInterface service is missing when using oauth2 module with expressive 3
Sorry for opening this new issue but I really think it's a bug in the oauth2 module or an incomplete documentation.
I followed the instructions and figured out my problem: The app crashes with a ServiceNotCreatedException and the message "AuthenticationInterface service is missing". But if I make a print_r($container) in routes.php, the interface is correctly listed under aliases.
config/autoload/dependencies.global.php
<?php
declare(strict_types=1);
use Zend\Expressive\Authentication;
return [
'dependencies' => [
'aliases' => [
Authentication\AuthenticationInterface::class => Authentication\OAuth2\OAuth2Adapter::class,
],
'invokables' => [
],
'factories' => [
],
],
];
config/autoload/oauth2.global.php
<?php
declare(strict_types=1);
use League\OAuth2\Server\Grant;
return [
'authentication' => [
'private_key' => dirname(__DIR__) . '/../data/oauth/private.key',
'public_key' => dirname(__DIR__) . '/../data/oauth/public.key',
'encryption_key' => require dirname(__DIR__) . '/../data/oauth/encryption.key',
'access_token_expire' => 'P1D',
'refresh_token_expire' => 'P1M',
'auth_code_expire' => 'PT10M',
'pdo' => [
'dsn' => sprintf(
'mysql:dbname=%s;host=%s',
false !== getenv('MYSQL_DB_NAME') ? getenv('MYSQL_DB_NAME') : '',
false !== getenv('MYSQL_DB_HOST') ? getenv('MYSQL_DB_HOST') : ''
),
'username' => false !== getenv('MYSQL_DB_USER') ? getenv('MYSQL_DB_USER') : '',
'password' => false !== getenv('MYSQL_DB_PASS') ? getenv('MYSQL_DB_PASS') : '',
],
'grants' => [
Grant\ClientCredentialsGrant::class => Grant\ClientCredentialsGrant::class,
Grant\PasswordGrant::class => Grant\PasswordGrant::class,
Grant\AuthCodeGrant::class => Grant\AuthCodeGrant::class,
Grant\ImplicitGrant::class => Grant\ImplicitGrant::class,
Grant\RefreshTokenGrant::class => Grant\RefreshTokenGrant::class,
],
],
];
config/routes.php
<?php
declare(strict_types=1);
use MyProject\Api\Handler\HomePageHandler;
use MyProject\Api\Handler\PingHandler;
use Psr\Container\ContainerInterface;
use Zend\Expressive\Application;
use Zend\Expressive\Authentication\AuthenticationMiddleware;
use Zend\Expressive\Authentication\OAuth2\TokenEndpointHandler;
use Zend\Expressive\MiddlewareFactory;
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
$app->post('/oauth2/token', TokenEndpointHandler::class);
$app->get('/', HomePageHandler::class, 'home');
$app->get('/api/ping', [
AuthenticationMiddleware::class,
PingHandler::class,
], 'api.ping');
};
- [ ] I was not able to find an open or closed issue matching what I'm seeing.
- [ ] This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
Provide a narrative description of what you are trying to accomplish.
Code to reproduce the issue
Expected results
Actual results
Originally posted by @kschroeer at https://github.com/zendframework/zend-expressive-authentication-oauth2/issues/61