我正在使用 OAuth 授权开发一个简单的 rest API。
我按照以下教程设置了所有内容(我从一个干净安装的 symfony 3 应用程序开始)
https://gist.github.com/tjamps/11d617a4b318d65ca583
安装完所有内容后,我通过以下方式更改了 config.yml
fos_oauth_server:
db_driver: orm
client_class: UserBundle\Entity\Client
access_token_class: UserBundle\Entity\AccessToken
refresh_token_class: UserBundle\Entity\RefreshToken
auth_code_class: UserBundle\Entity\AuthCode
service:
user_provider: fos_user.user_provider.username_email
我还更改了security.yml以允许登录时使用用户名和电子邮件
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
oauth_token: # Everyone can access the access token URL.
pattern: ^/oauth/v2/token
security: false
api:
pattern: ^/ # All URLs are protected
fos_oauth: true # OAuth2 protected resource
stateless: true # Do no set session cookies
anonymous: false # Anonymous access is not allowed
现在我收到以下错误:
致命错误:未捕获的异常“Symfony\Component\Debug\Exception\ContextErrorException”和消息“可捕获的致命错误:参数 5 传递给FOS\OAuthServerBundle\Storage\OAuthStorage::__construct()必须实现接口Symfony\Component\Security\Core\ User\UserProviderInterface,给定的 FOS\UserBundle\Doctrine\UserManager 实例,在/Users/%username/rai-api/var/cache/prod/appProdProjectContainer.php的第 1614 行调用,并在/Users/%username/中定义rai-api/vendor/friendsofsymfony/oauth-server-bundle/Storage/OAuthStorage.php 第 80 行
我正在使用 symfony 3.2