happyr/google-site-authenticator-bundle
Composer 安装命令:
composer require happyr/google-site-authenticator-bundle
包简介
Authenticate your website (not your users) with Google API. Can be used instead as Domain-Wide Delegation of Authority
README 文档
README
In some situations you want a website to make API request on the behalf of you (not your users). Example when you want to fetch website data from Google Analytics or upload database dumps to Google Drive. The solution Google offers for this is a Domain-Wide Delegation of Authority. But that solution requires you be a paying customer on Google Apps. I wanted a free solution so I created this bundle.
This bundle is using a normal OAuth for a web application, but it authenticates your google account (or accounts) but not your users'. It saves the access token in a cache until you manually revoke it.
Read all of this README file to understand how to get started and authenticated
Install
Use composer to get the bundle. You do also have to get a PSR-6 cache implementation.
$ php composer.phar require happyr/google-site-authenticator-bundle cache/redis-adapter
Activate this bundle in AppKernel.
new Happyr\GoogleSiteAuthenticatorBundle\HappyrGoogleSiteAuthenticatorBundle(),
Include the routing.yml and make sure it is protected from normal users.
// app/config/routing.yml happyr_google_site_authenticator: resource: "@HappyrGoogleSiteAuthenticatorBundle/Resources/config/routing.yml" prefix: /admin
Get API credentials
You will find all information on the Google Console. Go in to the console and click on "APIs" in the sidebar to select those API you want to use.
To retrieve the API-key and secret, click on "Credentials" in the sidebar and then "Create new ClientID". And create a client ID for a web application. Make sure to specify the correct Authorized redirect URIs. If you used the configuration above you should use the following url:
http://www.domain.com/admin/authenticate-google/return-url
When you are done you will get a client id and a client secret. Save those for the next section.
Configure
This bundle will fetch an access token and save it to cache. The PHPCacheAdapterBundle is an excellent bundle for this. You may use one of many predefined cache providers like; file_system, apc, mongodb etc. Read more about caching here: http://www.php-cache.com/
It also allows you to create your own cache provider. Here is an example configuration:
cache_adapter: providers: my_redis: factory: 'cache.factory.redis'
To configure the Happyr Google Site Authenticator bundle you need to add your API credentials and select a service
extending Psr\Cache\CacheItemInterface. If you are using the configuration
above you could use the following values:
happyr_google_site_authenticator: cache_service: 'cache.provider.my_redis' tokens: google_drive: client_id: '00000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com' client_secret: 'xxxxx-xxxxx_xxxxxxxxxxxx' redirect_url: 'http://www.domain.com/admin/authenticate-google/return-url' scopes: ['https://www.googleapis.com/auth/drive']
You will find all available scopes here.
The config above will configure a token called google_drive. You may, of course, configure more tokens. To get a Google_Client instance with those credentials:
$clientProvider = $this->get('happyr.google.client_provider'); $client = $clientProvider->getClient('google_drive'); // or don't use the client provider $client = $this->get('google.client.google_drive'); // if you only have one token configured $client = $this->get('google.client');
Authenticating
To make sure you fetch an access token you need to navigate to http://www.domain.com/admin/authenticate-google and
click on Authenticate. You will be asked to sign in with your Google account and grant the permissions. The access token
retrieved will be saved by the cache service. You want to make sure this is stored for a very long time.
When you are authenticated you may use happyr.google.client_provider to get an authenticated client.
happyr/google-site-authenticator-bundle 适用场景与选型建议
happyr/google-site-authenticator-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.16k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2014 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Authentication」 「google」 「Domain-Wide Delegation」 「Site-wide」 「Domain-Wide」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 happyr/google-site-authenticator-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 happyr/google-site-authenticator-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 happyr/google-site-authenticator-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
A PSR-7 compatible library for making CRUD API endpoints
Email Toolkit Plugin for CakePHP
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
统计信息
- 总下载量: 15.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-20