PHPackages                             xeroapi/xero-php-oauth2-app - 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. xeroapi/xero-php-oauth2-app

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

xeroapi/xero-php-oauth2-app
===========================

Xero OAuth 2.0 app for PHP

1.1.0(6y ago)219.1k↓57.4%25[2 issues](https://github.com/XeroAPI/xero-php-oauth2-app/issues)[3 PRs](https://github.com/XeroAPI/xero-php-oauth2-app/pulls)MITPHPCI passing

Since Dec 16Pushed 1y ago14 watchersCompare

[ Source](https://github.com/XeroAPI/xero-php-oauth2-app)[ Packagist](https://packagist.org/packages/xeroapi/xero-php-oauth2-app)[ RSS](/packages/xeroapi-xero-php-oauth2-app/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (3)Versions (20)Used By (0)

Xero PHP oAuth 2 App
====================

[](#xero-php-oauth-2-app)

This PHP project demonstrates how to use the xero-php-oauth2 SDK. Use composer or clone this repository to your local machine to begin.

You'll be able to connect to a Xero Organisation, make real API calls. The code used to make each API call will be displayed along with the results returned from Xero's API.

Getting Started
---------------

[](#getting-started)

To run locally, you'll need a local web server with PHP support.

- MAMP is a good option [Download MAMP](https://www.mamp.info/en/downloads/)

### Download Manually

[](#download-manually)

- Clone this repo into your local server webroot.
- Launch a terminal app and change to the newly cloned folder `xero-php-oauth2-app`
- Download dependencies with Composer using the following command

```
composer install

```

Create a Xero App
-----------------

[](#create-a-xero-app)

To obtain your API keys, follow these steps and create a Xero app

- Create a [free Xero user account](https://www.xero.com/us/signup/api/) (if you don't have one)
- Login to [Xero developer center](https://developer.xero.com/myapps)
- Click "New App" link
- Enter your App name, company url, privacy policy url.
- Enter the redirect URI (your callback url - i.e. `http://localhost:8888/xero-php-oauth2-app/callback.php`)
- Agree to terms and condition and click "Create App".
- Click "Generate a secret" button.
- Copy your client id and client secret and save for use later.
- Click the "Save" button. You secret is now hidden.

Configure your .env file
------------------------

[](#configure-your-env-file)

You'll need to setup your `.env` file

Rename the file `sample.env` to `.env` and copy and paste your *clientId, clientSecret and redirectUri* These .env variables will be read by authorization.php, callback.php, get.php.

Sample.env file

```
CLIENT_ID = "YOUR-CLIENT-ID"
CLIENT_SECRET = "YOUR-CLIENT-SECRET"
REDIRECT_URI = "http://localhost:8888/xero-php-oauth2-app/callback.php"
```

Sample PHP code from authorization.php

```
// This library will read variable from the .env file.
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$clientId = getenv('CLIENT_ID');
$clientSecret = getenv('CLIENT_SECRET');
$redirectUri = getenv('REDIRECT_URI');

$provider = new \League\OAuth2\Client\Provider\GenericProvider([
	'clientId'                => $clientId,
	'clientSecret'            => $clientSecret,
	'redirectUri'             => $redirectUri,
	'urlAuthorize'            => 'https://login.xero.com/identity/connect/authorize',
	'urlAccessToken'          => 'https://identity.xero.com/connect/token',
	'urlResourceOwnerDetails' => 'https://api.xero.com/api.xro/2.0/Organisation'
]);
```

docker-compose
--------------

[](#docker-compose)

- Have Docker &amp; Docker Compose installed -

Run `docker-compose up` in the root directory of this repository to launch a local server. The server will be published to port `8080` by default:

```
http://localhost:8080/

```

The redirect URL will be `http://localhost:8080/callback.php`, which must be set in the configuration of this demo application and within your Xero app.

The local port can be changed through the `APP_HTTP_PORT` variable in the environment or set in `.env`. You may want to do this if port `8080` is already in use.

License
-------

[](#license)

This software is published under the [MIT License](http://en.wikipedia.org/wiki/MIT_License).

```
Copyright (c) 2019 Xero Limited

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 58.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Total

5

Last Release

2307d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/227907?v=4)[xero harrison](/maintainers/xero)[@xero](https://github.com/xero)

![](https://www.gravatar.com/avatar/83931bcfcc9b95a2ac26b43e879b70c0e38d7dc6430c4c24d178fcc8af8fdc6c?d=identicon)[rettbehrensxero](/maintainers/rettbehrensxero)

![](https://www.gravatar.com/avatar/636affebe9d369bde025fa95a693e5d3cab4a1779dbfeb6966c12db41dc486c0?d=identicon)[manishT72x](/maintainers/manishT72x)

---

Top Contributors

[![SidneyAllen](https://avatars.githubusercontent.com/u/595967?v=4)](https://github.com/SidneyAllen "SidneyAllen (48 commits)")[![ibroker15](https://avatars.githubusercontent.com/u/11141022?v=4)](https://github.com/ibroker15 "ibroker15 (8 commits)")[![RettBehrens](https://avatars.githubusercontent.com/u/28675148?v=4)](https://github.com/RettBehrens "RettBehrens (7 commits)")[![pumpkinball](https://avatars.githubusercontent.com/u/91833653?v=4)](https://github.com/pumpkinball "pumpkinball (6 commits)")[![SerKnight](https://avatars.githubusercontent.com/u/2935387?v=4)](https://github.com/SerKnight "SerKnight (3 commits)")[![judgej](https://avatars.githubusercontent.com/u/395934?v=4)](https://github.com/judgej "judgej (3 commits)")[![sangeet-joy-tw](https://avatars.githubusercontent.com/u/157606431?v=4)](https://github.com/sangeet-joy-tw "sangeet-joy-tw (2 commits)")[![Raghunath-S-S-J](https://avatars.githubusercontent.com/u/100554147?v=4)](https://github.com/Raghunath-S-S-J "Raghunath-S-S-J (2 commits)")[![kensantoso](https://avatars.githubusercontent.com/u/9150185?v=4)](https://github.com/kensantoso "kensantoso (1 commits)")[![admo26](https://avatars.githubusercontent.com/u/10663462?v=4)](https://github.com/admo26 "admo26 (1 commits)")[![leegough](https://avatars.githubusercontent.com/u/25519426?v=4)](https://github.com/leegough "leegough (1 commits)")

### Embed Badge

![Health badge](/badges/xeroapi-xero-php-oauth2-app/health.svg)

```
[![Health](https://phpackages.com/badges/xeroapi-xero-php-oauth2-app/health.svg)](https://phpackages.com/packages/xeroapi-xero-php-oauth2-app)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[lion/bundle

Lion-framework configuration and initialization package

122.3k4](/packages/lion-bundle)[doppar/framework

The Doppar Framework

4012.4k14](/packages/doppar-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
