crevillo / ezsocialloginbundle
eZ Platform 的社交登录
Requires
- ezsystems/ezpublish-kernel: 7.*
- hwi/oauth-bundle: 0.6.*
Requires (Dev)
- phpunit/phpunit: ~4.7
- squizlabs/php_codesniffer: 2.*
This package is auto-updated.
Last update: 2024-09-23 05:08:13 UTC
README
eZ Social Login Bundle 为 eZ Platform 添加了对通过 OAuth1.0a 或 OAuth2 进行用户身份验证的支持。
它仅使用 HwiOauthBundle,因此您可以参考此文档包了解其内部工作原理。
安装
您可以通过 composer 安装此项目
composer require crevillo/ezsocialloginbundle
文档
您可以使用 HwiOauthBundle 文档 中列出的任何社交网络。请参阅该包以了解如何配置任何一种。
设置此包
A) 将 EzSocialLoginBundle 添加到您的项目中
composer require crevillo/ezsocialloginbundle:dev-master
B) 启用包
在内核中启用包,您还需要启用 HwiOauthBundle
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new HWI\Bundle\OAuthBundle\HWIOAuthBundle(), new Crevillo\EzSocialLoginBundle\CrevilloEzSocialLoginBundle() ); }
C) 导入路由
将 redirect.xml 和 login.xml 路由文件导入您的路由文件中。
# app/config/routing.yml hwi_oauth_redirect: resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml" prefix: /connect hwi_oauth_login: resource: "@HWIOAuthBundle/Resources/config/routing/login.xml" prefix: /login
注意
此包将覆盖 EzPublishCoreBundle 提供的默认用户登录模板。如果您的其他包也这样做,您可能不会看到任何变化。因此,如果您已经有自定义登录模板,请只需将 这些行 添加到模板的内容块中的任何位置。
D) 配置 Google 资源所有者
您需要修改您的 config.yml 文件,添加以下内容:
hwi_oauth: # list of names of the firewalls in which this bundle is active, this setting MUST be set firewall_names: [ezpublish_front]
接下来,您可以在 hwi_oauth > resource_owners 设置下添加您的 Google 应用信息和选项
hwi_oauth: # list of names of the firewalls in which this bundle is active, this setting MUST be set firewall_names: [ezpublish_front] resource_owners: your_google_app: type: google client_id: <your client id> client_secret: <your client secret> scope: "email profile"
E) 配置安全层
此包需要一个能够根据 OAuth 端点的用户响应加载用户的服务。它应该实现接口:HWI\Bundle\OAuthBundle\Security\Core\User\OAuthAwareUserProviderInterface。此包提供 此服务 作为起点,但您也可以自由创建自己的。
我们的 UserProvider 将尝试从社交网络中获取用户名。如果 eZ Platform 存储库中已经存在具有该用户名的任何用户,它将直接返回该用户。
如果没有用户具有该用户名,它将尝试在您的 "访客帐户" 用户组下创建新用户,并登录到该用户。
F) 配置 OAuth 防火墙
在防火墙配置中,您需要为之前配置的资源所有者配置一个登录路径。此外,您还需要将 OAuth 防火墙指向此包提供的服务
# app/config/security.yml security: firewalls: # your other firewalls # ezpublish_front: anonymous: ~ oauth: resource_owners: google: "/login/check-google" login_path: /login use_forward: false failure_path: /login oauth_user_provider: service: crevillo.ezsocialloginbundle.oauth_aware.user_provider.service
最后,您在上一步中定义的用于资源所有者的路径必须添加到您的路由中。
# app/config/routing.yml google_login: path: /login/check-google
- 实际上,这已手动测试,似乎适用于 Facebook、Twitter、Google 和 LinkedIn。
就这样!您可以自由尝试任何其他社交网络!。