cakephp-biztech/cakephp-xero-oauth2
Composer 安装命令:
composer require cakephp-biztech/cakephp-xero-oauth2
包简介
Xero Oauth2 API plugin for CakePHP 3.x
README 文档
README
This plugin provides access to Xero OAuth2 API for CakePHP. This plugin is wrapper around Xero PHP official SDK.
Requirements
- CakePHP 3.5 or greater
- PHP 5.6 or greater
Installation
-
You can install this plugin into your CakePHP application using composer
composer require cakephp-biztech/cakephp-xero-oauth2 -
After installation, load the plugin
Plugin::load('XeroOauth2', ['routes' => true]);
Or, you can load the plugin using the shell command:
bin/cake plugin load -r XeroOauth2 -
Run plugin migration to create table
bin/cake migrations migrate -p XeroOauth2
Setup
Now create new file to set your Xero App details.
-
Create new file
xero_config.phpinconfigdirectory:<?php return [ 'XeroOauth2' => [ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'baseUri' => 'https://example.com', 'scope' => [ 'openid', 'email', 'profile', 'offline_access', 'accounting.settings', 'accounting.contacts', // Any other scopes needed for your application goes here ], 'successUrl' => 'http://example.com/success' ] ];
Note: Do not forget to replace "https://example.com" with your website URL in your
config/xero_config.phpfile. -
After creating the configuration file, make sure to load the file in your
bootstrap.php:Configure::load('xero_config', 'default');
Important:
When you create your Xero API App you must have to specify 'OAuth 2.0 redirect URI' to https://your-website.com/xero-oauth2/callback (replace "https://your-website.com" with your website URL).
Usage
This plugin ships with XeroOauth component which can be used to get the instance of:
\XeroAPI\XeroPHP\Api\AccountingApiviaaccountingApi()method\XeroAPI\XeroPHP\Api\AssetApiviaassetApi()method\XeroAPI\XeroPHP\Api\IdentityApiviaidentityApi()method\XeroAPI\XeroPHP\Api\ProjectApiviaprojectApi()method
Load XeroOauth component:
$this->loadComponent('XeroOauth2.XeroOauth'); $accountingApi = $this->XeroOauth->accountingApi();
Once you have an instance of \XeroAPI\XeroPHP\Api\AccountingApi::class you're dealing directly with Xero's official SDK.
The Accounting API requires we pass through a tenant ID on each request. You can get value of that using Storage component. Also, you can get additional token details from this component as well.
$this->loadComponent('XeroOauth2.Storage'); $tenantId = $this->Storage->getXeroTenantId();
Following examples shows how to get contacts from Accounting API:
src/Controller/ContactsController.php
<?php namespace App\Controller; class ContactsController extends AppController { public function index() { $this->loadComponent('XeroOauth2.Storage'); $this->loadComponent('XeroOauth2.XeroOauth'); $tenantId = $this->Storage->getXeroTenantId(); $accountingApi = $this->XeroOauth->accountingApi(); foreach ($accountingApi->getContacts($tenantId)->getContacts() as $contact) { debug([ 'id' => $contact->getContactId(), 'name' => $contact->getName(), 'email' => $contact->getEmailAddress(), ]); } } }
You can also check XeroAPI Oauth2 App repository's example file.
Reference
- Official Xero PHP SDK: https://github.com/XeroAPI/xero-php-oauth2
- Example: https://github.com/XeroAPI/xero-php-oauth2-app/blob/master/example.php
Issues
Feel free to submit issues and enhancement requests.
cakephp-biztech/cakephp-xero-oauth2 适用场景与选型建议
cakephp-biztech/cakephp-xero-oauth2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.54k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「oauth2」 「cakephp」 「sdk」 「xero」 「cakephp-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cakephp-biztech/cakephp-xero-oauth2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cakephp-biztech/cakephp-xero-oauth2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cakephp-biztech/cakephp-xero-oauth2 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
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
Email Toolkit Plugin for CakePHP
Rhino, a CMS and Application-Framework plugin for CakePHP
A CakePHP plugin for sending mail via SparkPost's REST API
统计信息
- 总下载量: 1.54k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-04