我一直在尝试使用此捆绑包和Auth0在Symfony4项目中实施用户管理。当前,我有两个问题:其中一个是,当我注销时受到以下提示:没有用户“ HWI \ Bundle \ OAuthBundle \ Security \ Core \ User \ OAuthUser”的用户提供程序。这是在使用路径 / auth0 / logout 时。事实是,我有一个扩展OAuthUser类的User类,我认为就足够了。不是吗(我在services.yaml文件中还具有默认的HWI OAuthUserProvider,但这是因为在其中禁用或启用它似乎没有任何改变。)
我对如何设置用户提供程序以及文档令人困惑感到非常困惑(我一直使用教程中的文件,即资源所有者,直到我的高级开发人员向我展示了推荐的文件例如,实际的回购是非常不同的。)因此,这就是我到目前为止的内容:
services.yaml
<form method="post" enctype="multipart/form-data" id="formUpload">
<input type="file" name="file" required id="id_file">
</form>
<script>
$(".js-crop-and-upload").click(function () {
var form_upload = $("#formUpload")[0];
var form_data = new FormData(form_upload);
form_data.append('some', "some_val");
$.ajax({
url:'/accounts/crop/',
type:'post',
dataType:'json',
cache:false,
processData: false,
contentType: false,
data:form_data,
success:function (data) {
console.log(data)
}
});
</script>
security.yaml
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
hwi_oauth.user.provider.entity:
class: HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider
my.oauth_user_provider:
class: App\Providers\OAuthProvider
autowire: false
arguments:
- '@session'
- '@doctrine'
- '@service_container'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
App\EventListener\:
resource: '../src/EventListener'
# App\EventListener\UserEventListener:
# tags:
# - { name: 'kernel.event_listener', event: 'hwi_oauth.connect.completed' }
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
hwi_oauth.yaml
security:
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# in_memory: { memory: ~ }
# user_provider:
# entity:
# class: App\Entity\User
# property: email
my_provider:
id: my.oauth_user_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# main:
# pattern: ^/
# anonymous: ~
# http_basic: ~
# provider: user_provider
# form_login:
# login_path: login
# check_path: login
secured_area:
pattern: ^/
anonymous: ~
oauth:
resource_owners:
auth0: "/auth0/callback"
login_path: /login
use_forward: false
failure_path: /login
oauth_user_provider:
service: my.oauth_user_provider
logout:
path: /auth0/logout
target: /
main:
anonymous: ~
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secured, roles: ROLE_OAUTH_USER }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_DEVELOPER: ROLE_ADMIN
encoders:
App\Entity\User: bcrypt
我真的对这里发生的事情感到困惑。我想念什么?而且,如果在文档中,有人可以指出我解决方案的具体描述吗?我已经在Stack Overflow上查看了几个问题,但是他们谈论的是我未使用的Symfony 2,或者他们有不适用的答案,例如在<的提供程序下添加“ hwi_oauth.user.provider” strong> security.yaml ,但是如果我这样做,就会遇到提供商过多的问题。 (并且,如果我尝试通过说“ provider”而不是“ oauth_user_provider”来显式设置提供程序,那么这将使我陷入困境,说未配置子节点,并且在搜索中我没有发现任何要解释的东西错误消息的含义。)我正要撕掉我遗漏的那只小头发。我想念什么?我没有阅读或误读了文档的哪一部分?我不确定接下来要去哪里。
答案 0 :(得分:0)
事实证明,即使我的User类扩展了OAuthUser类,我的用户提供者扩展了HWI的用户提供者,我的用户提供者也正在调用仅在默认状态下的函数(loadUserByUsername),所以我有了只需在自己的提供程序中编写自己的代码即可覆盖该代码。这就解决了一个问题,但是现在我必须弄清楚为什么登录时我的User都为NULL。我认为那是一个单独的问题。