PHPackages                             allangallop/laravel-xero-oauth2-multi-tenant - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. allangallop/laravel-xero-oauth2-multi-tenant

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

allangallop/laravel-xero-oauth2-multi-tenant
============================================

A fork of webfox/laravel-xero-oauth2 that permits mutli-tenant usage

3.0.1(3y ago)06MITPHPPHP ^7.3|^8.0|^8.1

Since Jan 26Pushed 3y agoCompare

[ Source](https://github.com/AllanGallop/laravel-xero-oauth2-multi-tenant)[ Packagist](https://packagist.org/packages/allangallop/laravel-xero-oauth2-multi-tenant)[ Docs](https://github.com/AllanGallop/laravel-xero-oauth2-multi-tenant)[ RSS](/packages/allangallop-laravel-xero-oauth2-multi-tenant/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (21)Used By (0)

A Laravel integration for Xero using the Oauth 2.0 spec
=======================================================

[](#a-laravel-integration-for-xero-using-the-oauth-20-spec)

[![Latest Version on Packagist](https://camo.githubusercontent.com/162461d7989ec17b870aa97174c2299f19f47526e18efbb2bdbe117aa0bd1c16/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6c616e67616c6c6f702f6c61726176656c2d7865726f2d6f61757468322d6d756c74692d74656e616e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/allangallop/laravel-xero-oauth2-multi-tenant)[![Total Downloads](https://camo.githubusercontent.com/728d29caf08bc1e47824d296126e24e6be4e94e5d3bd83fccc63dfdb33640ad9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6c616e67616c6c6f702f6c61726176656c2d7865726f2d6f61757468322d6d756c74692d74656e616e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/allangallop/laravel-xero-oauth2-multi-tenant)

This package integrates the new recommended package of [xeroapi/xero-php-oauth2](https://github.com/XeroAPI/xero-php-oauth2) using the Oauth 2.0 spec with Laravel.

Installation
------------

[](#installation)

You can install this package via composer using the following command:

```
composer require allangallop/laravel-xero-oauth2-multi-tenant

```

The package will automatically register itself.

You should add your Xero keys to your `.env` file using the following keys:

```
XERO_CLIENT_ID=
XERO_CLIENT_SECRET=

```

(on [Xero developer portal](https://developer.xero.com/app/manage)): ***IMPORTANT*** When setting up the application in Xero ensure your redirect url is:

```
https://{your-domain}/xero/auth/callback

```

*(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:

```
php artisan vendor:publish --provider="Webfox\Xero\XeroServiceProvider" --tag="config"

```

Scopes
------

[](#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](https://developer.xero.com/documentation/oauth2/scopes).

Using the Package
-----------------

[](#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](https://github.com/XeroAPI/xero-php-oauth2/tree/master/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*

```
