Download the PHP package webfox/laravel-xero-oauth2 without Composer
On this page you can find all versions of the php package webfox/laravel-xero-oauth2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webfox/laravel-xero-oauth2
More information about webfox/laravel-xero-oauth2
Files in webfox/laravel-xero-oauth2
Package laravel-xero-oauth2
Short Description A Laravel integration for Xero using the Oauth 2.0 spec
License MIT
Homepage https://github.com/webfox/laravel-xero-oauth2
Informations about the package laravel-xero-oauth2
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
Error Handling
In the event that a user denies access on the Xero Authorisation page, the package will throw a OAuthException
from the AuthorizationCallbackController. This can be caught and acted upon however you prefer.
Laravel 11
To do this in Laravel 11, bind a custom exception renderer in bootstrap/app.php
:
Laravel 8-10
Use the reportable
method in the App\Exceptions\Handler
class:
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 with dependencies
xeroapi/xero-php-oauth2 Version ^2.0|^3.0|^4.0|^5.0|^6.0|^7.0
laravel/framework Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0