我目前正在尝试phpleague/oauth-server
在 symfony 3.3 项目中设置。出于这个原因,我想指定AuthorizationServer
作为服务能够从容器中加载它(而不是在它使用的任何地方设置整个东西)。
要将其设置AuthorizationServer
为服务,我需要将多个存储库作为参数注入。
这是 的服务定义AuthorizationServer
:
app.oauth2.authorization_server:
class: League\OAuth2\Server\AuthorizationServer
arguments: ["@app.oauth2.client_repository", "@app.oauth2.access_token_repository", "@app.oauth2.scope_repository", "%oauth_private_key%", "%oauth_encryption_key%"]
configurator: "app.oauth2.authorization_server.configurator:configure"
存储库的当前定义如下所示:
app.oauth2.client_repository:
class: Appbundle\Repository\OAuth2\ClientRepository
factory: 'doctrine.orm.entity_manager:getRepository'
arguments: [AppBundle\Entity\OAuth2\Client]
...
我尝试了许多将存储库定义为服务的方法,但每次我得到同样的错误:
Type error: Argument 1 passed to League\\OAuth2\\Server\\AuthorizationServer::__construct() must be an instance of League\\OAuth2\\Server\\Repositories\\ClientRepositoryInterface, instance of Doctrine\\ORM\\EntityRepository given
这是 ClientRepository 的样子:
<?php
namespace AppBundle\Repository\OAuth2;
use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
class ClientRepository implements ClientRepositoryInterface
{
/**
* Get a client.
*
* @param string $clientIdentifier The client's identifier
* @param string $grantType The grant type used
* @param null|string $clientSecret The client's secret (if sent)
* @param bool $mustValidateSecret If true the client must attempt to validate the secret if the client
* is confidential
*
* @return ClientEntityInterface
*/
public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true)
{
// TODO: Implement getClientEntity() method.
}
}
以下是我尝试实现它的其他一些方法:
https://matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/
他们都没有工作。你们有谁知道为什么我的存储库的服务定义不被接受为有效的输入AuthorizationServer
?
你的,FMK