Я пытаюсь реализовать HWIOAuthBundle без FOSUserBundle. До сих пор мне удалось перенаправить на страницу facebook, но когда я возвращаюсь назад к symfony, я получаю пустой ответ в URL-адресе, такой как (в localhost): http://site.local/# = __. Я попытался напечатать ответ от loadUserByOAuthUserResponse в моем классе App \ Security \ OAuthUserProvider, но опять ничего не печатается (у меня есть сомнение, вызывается ли он или нет). Я прочитал аналогичный вопрос здесь , но безуспешно
Я вставляю ниже важные сектора в моих файлах:
Security.yaml
security:
encoders:
MsgPhp\User\Infrastructure\Security\UserIdentity: 'argon2i'
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
msgphp_user: { id: MsgPhp\User\Infrastructure\Security\UserIdentityProvider }
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
id: App\Security\OauthUserProvider
users:
entity:
class: App\Entity\User
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
provider: msgphp_user
oauth:
resource_owners:
facebook: "/login/check-facebook"
google: "/login/check-google"
# my_custom_provider: "/login/check-custom"
# my_github: "/login/check-github"
login_path: /profile
use_forward: false
failure_path: /register
default_target_path: /profile
oauth_user_provider:
service: hwi_oauth.user.provider
# activate different ways to authenticate
# http_basic: true
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
# https://symfony.com/doc/current/security/form_login_setup.html
form_login:
login_path: /
check_path: /
default_target_path: /profile
username_parameter: email
password_parameter: password
logout:
path: logout
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/profile, roles: ROLE_TRAVELER }
hwi_oauth.yaml
hwi_oauth:
# list of names of the firewalls in which this bundle is active, this setting MUST be set
firewall_names: [main]
resource_owners:
facebook:
type: facebook
client_id: '%env(FB_ID)%'
client_secret: '%env(FB_SECRET)%'
scope: "email"
infos_url: "https://graph.facebook.com/me?fields=id,name,email,picture.type(square)"
paths:
email: email
profilepicture: picture.data.url
options:
display: popup
csrf: true
hwi_oauth_routing.yaml
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /redirect
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login
facebook_login:
path: /login/check-facebook
google_login:
path: /login/check-google
services.yaml
services:
# default configuration for services in *this* file
_defaults:
autowire: true
autoconfigure: true
public: false
hwi_oauth.user.provider:
class: App\Security\OAuthUserProvider
rout.yaml
# virtual routes
logout:
path: /logout
methods: GET
api_login:
path: /api/login
methods: POST
oauth_login_check:
path: /login-check/{resource}
App \ Security \ OAuthUserProvider
namespace App\Security;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Doctrine\ORM\EntityManagerInterface;
use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface;
use App\Entity\User;
class OauthUserProvider implements UserProviderInterface, OAuthAwareUserProviderInterface
{
private $em;
private $property = 'email';
/**
* @return UserInterface
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
print_r($response);
return $this->loadUserByUsername($response->getEmail());
}