我安装了带有自定义身份验证提供程序的fosOauthServerBundle(避免FosUserBundle)。
我的服务的配置似乎不准确,所以捆绑包找不到用户提供商:
对空上的成员函数loadUserByUsername()的调用
参考:vendor\friendsofsymfony\oauth-server bundle\Storage\OAuthStorage.php(第162行)
try {
$user = $this->userProvider->loadUserByUsername($username);
} catch (AuthenticationException $e) {
return false;
}
希望一篇帖子已经处理了这种错误,但它并不建议明确的解决方案:
上一个主题相同的问题
我使用的是文档中的实体提供程序,它可以完美地使用除使用fosoauth授予密码之外的所有内容(令人沮丧):实体用户-提供商链接
实际上,我尝试了几种方法在配置服务中编写它,但无法使其工作。有人能向我提出解决方案吗?
我尝试过app_user_provider.email或app_user.provider.username,但也不起作用。
security:
encoders:
AppEntityUser:
algorithm: bcrypt
#FOSUserBundleModelUserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER, ROLE_ESTABLISHMENT
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
app_user_provider:
entity:
class: AppEntityUser
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
oauth_token:
pattern: ^/oauth/v2/token
security: false
# Add this firewall only in the Authorization code flow
oauth_authorize:
pattern: ^/oauth/v2/auth
form_login:
provider: app_user_provider
check_path: /oauth/v2/auth_login_check
login_path: /oauth/v2/auth_login
anonymous: true
api_doc:
pattern: ^/api/doc
fos_oauth: false
stateless: true
anonymous: true
api:
pattern: ^/api
fos_oauth: true
stateless: true
anonymous: false
main:
pattern: ^/
form_login:
provider: app_user_provider
csrf_token_generator: security.csrf.token_manager
#logout: true
guard:
authenticators:
- AppSecurityLoginFormAuthenticator
remember_me:
secret: '%kernel.secret%'
lifetime: 604800 # 1 week in seconds
path: /
always_remember_me: true
logout:
path: app_logout
target: app_login
fos_oauth: false
anonymous: true
access_control:
- { path: ^/oauth/v2/auth_login$, role: IS_AUTHENTICATED_ANONYMOUSLY } # Add this only in the Authorization code flow
- { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/establishment, role: IS_AUTHENTICATED_ANONYMOUSLY }
fos_oauth_server:
db_driver: orm
client_class: AppEntityClient
access_token_class: AppEntityAccessToken
refresh_token_class: AppEntityRefreshToken
auth_code_class: AppEntityAuthCode
service:
#user_provider: fos_user.user_provider.username
user_provider: app_user_provider
那会救我一天的,谢谢!
好吧,我只需要创建一个自定义用户提供程序。它无法在实体上工作。
https://symfony.com/doc/current/security/user_provider.html#creating-a定制用户-供应商