![](/img/trans.png)
[英]FOSOAuthServerBundle with FOSUserBundle - How to make it works?
[英]How to configure FOSUserBundle to be the authentication provider for my FOSOAuthServerBundle enabled server
我正在尝试将FOSUserBundle
设置为启用FOSOAuthServerBundle
的服务器的身份验证提供程序。 在我尝试实施FOSUserBundle
之前, FOSOAuthServerBundle
一直在正常工作,我也让FOSUserBundle
在没有FOSOAuthServerBundle
的情况下工作,但我就是无法让它们一起工作。
我的问题是在下面的security.yml
中的oauth_authorize
: 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 身份验证”}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.