betterbrief / silverstripe-opauth
SilverStripe 3.1 OpAuth 模块。查看:http://opauth.org/
Requires
- opauth/opauth: ^1.0.0
- silverstripe/framework: ~3.1
Requires (Dev)
- phpunit/phpunit: ~3.7
This package is not auto-updated.
Last update: 2024-08-17 12:44:51 UTC
README
此模块依赖于不再维护的 Opauth - 我们不建议继续使用此模块,因为我们不再积极开发它。
SilverStripe Opauth 模块
简介
使用 Opauth 库 以轻松实现社交登录策略。查看他们的 文档
当前状态
1.1 - 稳定版。没有已知的重大问题。使用 错误追踪器 报告问题。
它是如何工作的?
该模块提供了一个额外的登录表单,开发人员可以控制它,允许用户使用任何 Oauth 提供商提供的身份即时登录到您的网站。每个提供商都使用 OpauthStrategy
处理,其中许多是免费提供的。有 Facebook、Twitter、Google 以及更多策略。
基于 Oauth 提供商的身份数据,该模块将根据身份中提供的电子邮件地址查找或创建一个新的 Member
对象。这也意味着会员可以有一个或多个 Oauth 身份链接到一个单独的账户;这些保存到 OpauthIdentity
对象中。
如果从提供者响应生成的 Member
没有电子邮件地址或任何其他所需的数据,内置了处理此情况的功能。您可以通过将 OpauthValidator
的 custom_validator
属性设置为所需的验证器类的名称,来强制执行所需字段或任何其他类型的验证。
除此之外,用户流程相当简单。如果所有所需数据都存在,则使用 Member::login
登录会员,然后重定向到他们正在查看的页面或默认目的地,这可以在您的配置中设置 - 就像默认的 MemberAuthenticator
一样。
要求
- SilverStripe 3.1(也许 3.0,但尚未测试)
- 至少一个 Opauth 策略
- 最好,在 php.ini 中启用 allow_url_fopen。我们已经编写了一个自定义 cURL 旁路程序,它适用于 Twitter、Google 和 Facebook 策略,但它属于专有技术。
- 为了扩展 cURL 支持,我们依赖于一个 Opauth 分支
常见问题解答
此模块包含什么?
它包含以下内容:
- Opauth 核心(见下文);
OpauthAuthenticator
:旨在与MemberAuthenticator
相似;OpauthLoginForm
:提供不同的认证方式;OpauthRegisterForm
:如果配置,提供中间步骤,以便不完整的OpauthIdentity
认证会员可以填写所需的其他信息;OpauthController
:作为策略之间通信的中介;OpauthIdentity
:作为与Member
对象的通用接口,可以将 Oauth 身份保存到其中。这些在成功登录后与Member
关联,以便提供者的 UID 和签名响应作为密钥。
注意:Opauth 的维护者建议按需包含策略,而不是将它们捆绑在一起。
在哪里可以获取策略?
您可以在“可用策略”标题下找到一份列表,请访问Opauth 主页
Packagist 提供了一份策略列表,您可以通过 Composer 进行安装。
策略应该放在哪里?
使用 composer 需求您的策略
如何将 API 响应映射到 Member
?
您在 _config.yml
中定义 OpauthIdentity
的 member_mapper
块。只需提供一个成员字段到 Opauth 响应数组点符号路径的哈希表,对于简单字段,或者如果您需要执行一些解析以获取所需的值,则可以提供一个类名和函数的数组,例如 ['OpauthResponseHelper', 'get_first_name']
。它接受认证响应数组作为参数。请参阅下面的示例 YAML 配置以获取更多详细信息。
如何配置模块及其策略?
所有 Opauth 特定的配置变量都可以放在 opauth_settings
下,并直接传递给 Opauth
。
您可以将这些设置放在您的 _config.yml
文件中。此外,由于您的策略 API 详细信息可能会根据域名和环境而变化,您可以使用 Config
API 更新这些设置。请参阅Opauth 配置文档。以下是一些示例以帮助您
_config.yml
示例
--- Name: silverstripe-opauth After: 'framework/*','cms/*' --- # see the Opauth docs for the config settings - https://github.com/opauth/opauth/wiki/Opauth-configuration#configuration-array OpauthAuthenticator: opauth_settings: #Register your strategies here #Including any extra config Strategy: Facebook: app_id: '' app_secret: '' scope: email Google: client_id: '' client_secret: '' Twitter: key: '' secret: '' security_salt: 'correct horse battery staple' security_iteration: 500 security_timeout: '2 minutes' callback_transport: 'session' #Configuration for the Identity-Member mapping OpauthIdentity: member_mapper: Facebook: FirstName: 'info.first_name' Surname: 'info.last_name' Locale: 'raw.locale' Email: 'info.email' Twitter: FirstName: ['OpauthResponseHelper', 'get_first_name'] Surname: ['OpauthResponseHelper', 'get_last_name'] Locale: ['OpauthResponseHelper', 'get_twitter_locale'] Google: FirstName: 'info.first_name' Surname: 'info.last_name' Email: 'info.email' Locale: ['OpauthResponseHelper', 'get_google_locale']
_config.php
示例
//Register and configure strategies Config::inst()->update('OpauthAuthenticator', 'opauth_settings', array( 'Strategy' => array( 'Facebook' => array( 'app_id' => '', 'app_secret' => '', 'scope' => 'email', ), 'Google' => array( 'client_id' => '', 'client_secret' => '' ), 'Twitter' => array( 'key' => '', 'secret' => '' ), ), )); //Identity to member mapping settings per strategy Config::inst()->update('OpauthIdentity', 'member_mapper', array( 'Facebook' => array( 'FirstName' => 'info.first_name', 'Surname' => 'info.last_name', 'Locale' => 'raw.locale', 'Email' => 'info.email', ), 'Twitter' => array( 'FirstName' => array('OpauthResponseHelper', 'get_first_name'), 'Surname' => array('OpauthResponseHelper', 'get_last_name'), 'Locale' => array('OpauthResponseHelper', 'get_twitter_locale'), ), 'Google' => array( 'FirstName' => 'info.first_name', 'Surname' => 'info.last_name', 'Email' => 'info.email', 'Locale' => array('OpauthResponseHelper', 'get_google_locale'), ), ));
注意:如您所见,策略配置设置有时命名不一致 - 对于这一点我们无法提供帮助,对此表示歉意!
文档
提出问题和建议改进
如果您发现错误或有一个非常好的想法,请提出问题。更好的是,如果您可以修复错误,那么请随意提交一个 pull request,带上修复代码,理想情况下要尊重到目前为止使用的编码约定。
归属
- Opauth 由 U-Zyn Chua 以 MIT 许可证提供(http://uzyn.com)版权所有 © 2012-2013