Hi there,
I an using cakePHP 5.2.7. and registred in my Application.php a service:
$container
->add(GenericProvider::class, function () {
return new GenericProvider([
'clientId' => 'xxx',
'clientSecret' => 'xxx',
'redirectUri' => 'https://account.xyz.com/oauth/callback',
'urlAuthorize' => 'https://auth.xyz.com/authorize',
'urlAccessToken' => 'https://auth.xyz.com/token',
'urlResourceOwnerDetails' => 'https://auth.xyz.com/userinfo',
'pkceMethod' => GenericProvider::PKCE_METHOD_S256,
]);
});
Some of you may recognize this is e generic league/oauth2-client.
I also build a small Component: OauthComponent.php to do some basic tasks.
Now I want to inject the GenericProvider::class into the OauthComponent.php.
In the official documentation, I found this:
Dependency Injection - 5.x
For me, this means I have to do it in Application::service like this way:
$container->add(OauthComponent::class)
->addArgument(ComponentRegistry::class)
->addArgument(GenericProvider::class);
and can get the GenericProvider by constructor:
class OauthComponent extends Component
{
protected GenericProvider $provider; // OAuth2-client
public function __construct(ComponentRegistry $registry, GenericProvider $provider, array $config = [])
{
parent::__construct($registry, $config);
$this->provider = $provider;
}
...
...
}
But now I get the error:
App\Controller\Component\OauthComponent::__construct(): Argument #3 ($config) must be of type array, Cake\Controller\ComponentRegistry given
and when I toggle the arguments of [internal]in App\Controller\Component\OauthComponent->__construct I can see the following:
object(Cake\Controller\ComponentRegistry) {
}object(League\OAuth2\Client\Provider\GenericProvider) {
}object(Cake\Controller\ComponentRegistry) {
}object(League\OAuth2\Client\Provider\GenericProvider) {
}[ ]
It looks like ComponentRegistry and GenericProvider are registered twice and during injecting it into the compoent, first 3 arguments are used which will mean that the empty array (last argument) is not assigned correctly.
Any ideas? Many thanks to all whe read this ![]()