[英]Setup Facebook login with HWIOAuthBundle, symfony 3
我正在使用HWIOAuthBundle設置Facebook登錄名,但是在運行路徑時:
http:// localhost:8000 / connect或
http:// localhost:8000 / connect / check-facebook
他無法加載頁面,沒有錯誤消息,只是一個網絡瀏覽器錯誤
:ERR_TOO_MANY_REDIRECTS
routing.yml
api:
resource: '.'
type: 'api_platform'
app:
resource: '@AppBundle/Action/'
type: 'annotation'
api_login_check:
path: /api/login_check
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /connect
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /connect
facebook_login:
path: /connect/check-facebook
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /account/register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
安全性
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_READER: ROLE_USER
ROLE_ADMIN: ROLE_READER
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
login:
pattern: ^/login
stateless: true
anonymous: true
provider: fos_userbundle
form_login:
check_path: /login_check
username_parameter: _username
password_parameter: _password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_id: form.csrf_provider
login_path: /login
check_path: /login_check
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
oauth:
resource_owners:
facebook: "/connect/check-facebook"
login_path: /connect
use_forward: false
failure_path: /connect
default_target_path: /
oauth_user_provider:
service: hwi_oauth.user.provider.fosub_bridge
lexik_jwt: ~
logout:
path: /logout
target: /login
anonymous: true
stateless: true
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
access_control:
- { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/books, roles: [ ROLE_READER ] }
- { path: ^/, roles: [ ROLE_READER ] }
- { path: ^/logout, role: IS_AUTHENTICATED_ANONYMOUSLY }
配置文件
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# Nelmio CORS
nelmio_cors:
defaults:
allow_origin: ["%cors_allow_origin%"]
allow_methods: ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
allow_headers: ["content-type", "authorization"]
expose_headers: ["link"]
max_age: 3600
paths:
'^/': ~
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AppBundle\Entity\User
use_username_form_type: false
lexik_jwt_authentication:
private_key_path: '%jwt_private_key_path%'
public_key_path: '%jwt_public_key_path%'
pass_phrase: '%jwt_key_pass_phrase%'
token_ttl: '%jwt_token_ttl%'
hwi_oauth:
connect:
confirmation: true
registration_form: fos_user.registration.form.factory
firewall_names: [main]
fosub:
username_iterations: 30
properties:
facebook: facebookID
resource_owners:
# Facebook Access
facebook:
type: facebook
client_id: '%oauth.facebook.id%'
client_secret: '%oauth.facebook.secret%'
scope: "email"
options:
display: popup
csrf: true
我不確定這是否是造成此問題的原因,但乍一看,我認為您忘記了配置OAuth防火牆,以使/connect
和/connect/check-facebook
路由可供匿名用戶訪問。
因此,您應該添加您的security.yml
:
access_control:
- { path: ^/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/connect/check-facebook, role: IS_AUTHENTICATED_ANONYMOUSLY }
為防止意外沖突,還建議在app/config/routing.yml
第一位置“導入”所有OAuth路由:
為防止出現奇怪的問題,此路由應在您的自定義路由之前導入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.