我正在尝试将FOSUserBundle
设置为我启用FOSOAuthServerBundle
的服务器的身份验证提供程序。 FOSOAuthServerBundle
在我尝试实施FOSUserBundle
之前一直正常工作,我也有FOSUserBundle
工作没有FOSOAuthServerBundle
,但我只是不能让他们一起工作。
我的问题是应该在下面的oauth_authorize
中的security.yml
:firewall中为身份验证提供程序指定什么?
# app/config/security.yml
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username
encoders:
FOS\UserBundle\Model\UserInterface: sha512
firewalls:
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
# WHAT GOES HERE?
api:
pattern: ^/api
fos_oauth: true
stateless: true
access_control:
- { path: ^/api, roles: [ IS_AUTHENTICATED_FULLY ] }
我试图验证用户而不是客户端。
非常感谢。
您应该在config.yml中包含以下内容
fos_user:
db_driver: orm
firewall_name: main
user_class: Zoef\UserBundle\Entity\Userere
oauth服务器就像这样
fos_oauth_server:
db_driver: orm
client_class: {PATH TO ENTITY}\Client
access_token_class: {PATH TO ENTITY}\AccessToken
refresh_token_class: {PATH TO ENTITY}\RefreshToken
auth_code_class: {PATH TO ENTITY}\AuthCode
service:
user_provider: fos_user.user_provider.username
而security.yml应如下所示:
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
oauth_token:
pattern: ^/oauth/v2/token
security: false
access_control:
- { path: ^/, roles: ROLE_ADMIN }
您可以测试它是否有效,因为当您到达任何URL时,您应该得到如下响应:
{“error”:“access_denied”,“error_description”:“需要OAuth2身份验证”}