Download the PHP package allangallop/laravel-xero-oauth2-multi-tenant without Composer
On this page you can find all versions of the php package allangallop/laravel-xero-oauth2-multi-tenant. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download allangallop/laravel-xero-oauth2-multi-tenant
More information about allangallop/laravel-xero-oauth2-multi-tenant
Files in allangallop/laravel-xero-oauth2-multi-tenant
Package laravel-xero-oauth2-multi-tenant
Short Description A fork of webfox/laravel-xero-oauth2 that permits mutli-tenant usage
License MIT
Homepage https://github.com/AllanGallop/laravel-xero-oauth2-multi-tenant
Informations about the package laravel-xero-oauth2-multi-tenant
A Laravel integration for Xero using the Oauth 2.0 spec
This package integrates the new recommended package of xeroapi/xero-php-oauth2 using the Oauth 2.0 spec with Laravel.
Installation
You can install this package via composer using the following command:
The package will automatically register itself.
You should add your Xero keys to your .env
file using the following keys:
(on Xero developer portal): IMPORTANT When setting up the application in Xero ensure your redirect url is:
(The flow is xero/auth/callback performs the oAuth handshake and stores your token, then redirects you over to your success callback)
You can publish the configuration file with:
Scopes
You'll want to set the scopes required for your application in the config file.
The default set of scopes are openid
, email
, profile
, offline_access
, and accounting.settings
.
You can see all available scopes on the official Xero documentation.
Using the Package
This package registers two bindings into the service container you'll be interested in:
\XeroAPI\XeroPHP\Api\AccountingApi::class
this is the main api for Xero - see the xeroapi/xero-php-oauth2 docs for usage. When you first resolve this dependency if the stored credentials are expired it will automatically refresh the token.Webfox\Xero\OauthCredentialManager
this is the credential manager - The Accounting API requires we pass through a tenant ID on each request, this class is how you'd access that. This is also where we can get information about the authenticating user. See below for an example.
app\Http\Controllers\XeroController.php
resources\views\xero.blade.php
routes/web.php
Multi-Tenant
For multi-tenant scenerios you can call the method getTenants()
from the Webfox\Xero\OauthCredentialManager
which will return an array of currently connected organisations
Likewise getTenantId()
has been extended to accept the index key as a parameter (defaults to 0 if left empty)
These provide the means to implement your own logic for multi-tenant organisations, for example:
Credential Storage
Credentials are stored in a JSON file using the default disk on the Laravel Filesystem, with visibility set to private. This allows credential sharing across multiple servers using a shared disk such as S3, regardless of which server conducted the OAuth flow.
To use a different disk, change the xero.credential_disk
config item to another disk defined in config/filesystem.php
.
You can switch out the credential store (e.g. for your own UserStore
if you wanted to store
the credentials against your user) in one of two ways:
- If it's a simple store and Laravel can automatically resolve your bindings, simply change the
xero.credential_store
config key to point to your new implementation. - If it requires more advanced logic (e.g. using the current user to retrieve the credentials) then you can rebind this
in your
AppServiceProvider
or a Middleware e.g.
An example UserStorageProvider can been found here
Using Webhooks
On your application in the Xero developer portal create a webhook to get your webhook key.
You can then add this to your .env
file as
You can then setup a controller to handle your webhook and inject \Webfox\Xero\Webhook
e.g.
Example calls
This package is simply a bridge so you don't have to deal with the Oauth2 gymnastics in Laravel.
Once you've have an instance of \XeroAPI\XeroPHP\Api\AccountingApi::class you're dealing directly with Xero's api library.
The XeroAPI PHP Oauth2 App repository has this list of examples of implementing calls to the API: e.g. invoice creation etc.
https://github.com/XeroAPI/xero-php-oauth2-app/blob/master/example.php
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-xero-oauth2-multi-tenant with dependencies
xeroapi/xero-php-oauth2 Version ^2.0
laravel/framework Version ^6.0|^7.0|^8.0|^9.0