azine / hybridauth-bundle
一个用于通过Xing和LinkedIn API访问个人资料的Symfony2扩展包,使用HybridAuth
Requires
- php: >=5.3.2
- hybridauth/hybridauth: ~2.3.0
- monolog/monolog: ~1.6
- symfony/console: ~2.1
- symfony/finder: ~2.1
- symfony/framework-bundle: ~2.1
This package is auto-updated.
Last update: 2024-09-18 02:37:18 UTC
README
Symfony2扩展包,用于集成HybridAuth库以获取访问各种社交网络API的能力。
有关集成库的更多详细信息,请参阅https://github.com/hybridauth/hybridauth。
可用的API
有很多提供者可供选择。以下两个链接提供了完整列表
https://github.com/hybridauth/hybridauth/tree/master/hybridauth/Hybrid/Providers https://github.com/hybridauth/hybridauth/tree/master/additional-providers
安装
使用Composer安装AzineHybridAuthBundle,只需将以下内容添加到您的composer.json
文件中:
// composer.json
{
// ...
require: {
// ...
"azine/hybridauth-bundle": "dev-master"
}
}
然后,您可以通过在您的composer.json
文件所在目录中运行Composer的update命令来安装新的依赖项。
php composer.phar update
现在,Composer将自动下载所有必需的文件,并为您安装它们。剩下的只是更新您的AppKernel.php文件,并注册新的包。
<?php
// in AppKernel::registerBundles()
$bundles = array(
// ...
new Azine\HybridAuthBundle\AzineHybridAuthBundle(),
// ...
);
注册AzineHybridAuthBundle的路由
// in app/config/routing.yml
azine_hybrid_auth_bundle:
resource: "@AzineHybridAuthBundle/Resources/config/routing.yml"
prefix: /hybrid-auth/
如果您想将用户认证会话存储在数据库中,以便用户在下一个浏览器会话中自动重新连接,那么您需要在config.yml中启用此功能并更新您的数据库模式:
php app/console doctrine:schema:update --force
或者创建一个数据库迁移并应用它
php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
在您偏好的社交网络/提供者上创建应用
LinkedIn => https://www.linkedin.com/secure/developer
配置
至少配置一个提供者。请参阅上面的链接以获取可用提供者的列表。
"hybridauth\hybridauth\Hybrid\Providers"文件夹中的提供者默认可通过其ID访问,"hybridauth\additional-providers"文件夹中的提供者必须进行配置。=> 请参阅以下LinkedIn提供者的包装配置。
LinkedIn提供者实现了一些额外功能。对于其他所有提供者,都有HybridAuth提供的默认功能。
//app/config/config.yml
// Default configuration for "AzineHybridAuthBundle"
azine_hybrid_auth:
endpoint_route: azine_hybrid_auth_endpoint # the route_name where your endpoint controller (e.g. HybridEndPointController) is available
debug: false # set to true to log debug-information to the debug_file
debug_file: '%kernel.logs_dir%/hybrid_auth_%kernel.environment%.log' # location of the debug-file
store_for_user: false # set to true to store hybrid auth session data into your database for the logged in user
store_as_cookie: false # set to true if session-information should be stored as cookies (e.g. for anon. users)
providers:
# Prototype (at least one provider has to be defined)
name:
enabled: true
scope: ~ # comma-separated list of required 'access rights'
wrapper:
path: ~ # full path to the file containing the wrapper class
class: ~ # the wrapper class
keys:
key: ~ # your api-key for this provider
secret: ~ # your secret for this provider
以下是LinkedIn提供者的示例
//app/config/config.yml
azine_hybrid_auth:
linkedin:
enabled: true
scope: "r_ basicprofile, r_network"
keys:
key: %linkedin_api_key%
secret: %linkedin_api_secret%
在您的parameters.yml.dist文件中定义linkedin的密钥和秘密。
AzineMergedBusinessNetworksProvider
此服务/提供者提供了一些方便的方法来处理商业网络(LinkedIn)。所有方法都期望用户已“连接”到linkedin。如果用户尚未授权您的应用访问数据,则会直接通过设置html-header-location和调用“die”来输出http-redirect。
未缓存,未分页。
getLinkedInContacts()
获取当前用户的所有LinkedIn联系人。
未缓存,未分页。
截至2015年5月,LinkedIn限制了API访问。请参阅https://developer.linkedin.com/support/developer-program-transition
获取LinkedInContacts将仅适用于您是LinkedIn合作伙伴计划的一部分并且被允许访问的情况。请参阅https://developer.linkedin.com/partner-programs
getContactProfiles($pageSize = 50, $offset = 0)
获取当前用户的所有联系人。已缓存和分页。
函数getContactProfiles($pageSize = 50, $offset = 0)从商业网络获取一页的联系人。
第一次调用将比后续调用长得多,因为在第一次调用时,两个网络中的所有联系人都会被检索并存储在一个大数组中,按姓氏排序。然后,这个集合将被存储在用户会话中。
贡献
非常欢迎贡献。请分叉存储库,并将您的pull-request提交给master分支。
PR应该
- 包含PR解决的问题或添加到包中的内容(如有适用,参考现有问题)
- 包含干净的代码,一些内联文档和phpdocs,不要“纯空白”更改。
- 遵循Symfony最佳实践和编码风格
- 有phpunit测试覆盖新功能或修复
- 在提交PR之前,您的分支在travis-ci.org上应显示为“绿色”构建
代码风格
您可以使用php-cs-fixer
检查代码风格。您可以选择设置一个包含php-cs-fixer
检查的pre-commit钩子。另请参阅https://github.com/FriendsOfPHP/PHP-CS-Fixer
您只需将pre-commit.sample
文件从commit-hooks/
移动到.git/hooks/
文件夹,并将其重命名为pre-commit
。
php-cs-fixer
将在每次提交时检查您的代码风格,并对提交应用修复。
要手动运行php-cs-fixer
,请安装依赖关系(composer install
),并执行php vendor/friendsofphp/php-cs-fixer/php-cs-fixer --diff --dry-run -v fix --config=.php_cs.dist .