bybrand/oauth2-zohodesk
Composer 安装命令:
composer require bybrand/oauth2-zohodesk
包简介
Zoho Desk Provider for PHP League's OAuth 2.0 Client
README 文档
README
This package provides Zoho Desk OAuth 2.0 support for the PHP League's OAuth 2.0 Client.Initially, this module was used for the integration of Bybrand with Zoho Desk and is in production (needs improvement).
First, you can do get Client ID and Client Secret in "Zoho Developer console". Full documentation, can be see in Zoho documentation.
Installation
composer require bybrand/oauth2-zohodesk
Usage
This is a instruction base to get the token, and in then, to save in your database to future request. The method getResourceOwner return your first organization, via /api/v1/organizations. See more in Zoho Desk documentation Get all organizations
You do not need get getResourceOwner if you not need.
use Bybrand\OAuth2\Client\Provider\ZohoDesk as ProviderZohoDesk;;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
$params = $_GET;
$provider = new ProviderZohoDesk([
'clientId' => 'key-id',
'clientSecret' => 'secret-key',
'redirectUri' => 'your-url-redirect',
]);
if (!empty($params['error'])) {
// Got an error, probably user denied access
$message = 'Got error: ' . htmlspecialchars($params['error'], ENT_QUOTES, 'UTF-8');
// Return error.
echo $message;
}
if (!isset($params['code']) or empty($params['code'])) {
// If we don't have an authorization code then get one
$authorizationUrl = $provider->getAuthorizationUrl([
'scope' => [
'Desk.basic.READ',
]
]);
// Get state and store it to the session
$_SESSION['oauth2state'] = $provider->getState();
header('Location: '.$authorizationUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($params['state']) || ($params['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
// Set error and redirect.
echo 'Invalid stage';
} else {
try {
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $params['code']
]);
// Retriave a first Zoho Desk organization.
$organization = $provider->getResourceOwner($token);
} catch (IdentityProviderException $e) {
// Error, HTTP code Status
} catch (\Exception $e) {
// Error, make redirect or message.
}
// Save organization data.
$id = $organization->getId(),
$name = $organization->getOrganizationName(),
// Use this to interact with an API on the users behalf
echo $token->getToken();
}
Please, for more information see the PHP League's general usage examples.
Refreshing a Token
Zoho Desk token refresh is sent only with accessType set to offline. It is important to note that the refresh token is only returned on the first request after this it will be null.
You can do revoke access to get the token refresh in a second request. Visit https://accounts.zoho.com and navigate to Connected Apps.
$provider = new ProviderZohoDesk([
'clientId' => 'key-id',
'clientSecret' => 'secret-key',
'redirectUri' => 'your-url-redirect',
'accessType' => 'offline' // Use only for refresh token.
]);
$token = $provider->getAccessToken('authorization_code', [
'code' => $code
]);
// Persist the token in a database.
$refreshToken = $token->getRefreshToken();
See more details in Generating Access Token From a Refresh Token Zoho Desk Docs.
Testing
bash
$ ./vendor/bin/phpunit
or individual method test, by group.
bash
$ ./vendor/bin/phpunit --group=Zoho.GetResourceOwner
License
The MIT License (MIT). Please see License File for more information.
bybrand/oauth2-zohodesk 适用场景与选型建议
bybrand/oauth2-zohodesk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.39k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2018 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「authorization」 「api」 「Authentication」 「oauth2」 「Zoho」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bybrand/oauth2-zohodesk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bybrand/oauth2-zohodesk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bybrand/oauth2-zohodesk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A PSR-7 compatible library for making CRUD API endpoints
Laravel JWT auth service package
Zoho OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Alfabank REST API integration
统计信息
- 总下载量: 9.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-15