PHPackages                             calcinai/oauth2-xero - 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. calcinai/oauth2-xero

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

calcinai/oauth2-xero
====================

Xero OAuth 2.0 Client Provider for The PHP League OAuth2-Client

v1.3.1(2mo ago)93.1M↓20.3%14[4 issues](https://github.com/calcinai/oauth2-xero/issues)[1 PRs](https://github.com/calcinai/oauth2-xero/pulls)4MITPHPPHP &gt;=7.1.0CI failing

Since Jan 22Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/calcinai/oauth2-xero)[ Packagist](https://packagist.org/packages/calcinai/oauth2-xero)[ RSS](/packages/calcinai-oauth2-xero/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (4)

Xero Provider for OAuth 2.0 Client
==================================

[](#xero-provider-for-oauth-20-client)

[![Latest Version](https://camo.githubusercontent.com/04d51a00a41a9ac81ec0381b298e02827a66f97852a71a8b1396e36a75befbec/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f63616c63696e61692f6f61757468322d7865726f2e737667)](https://github.com/calcinai/oauth2-xero/releases)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/2bf25f8d67daa70ecd30e67408b697821ee765e95dfba0482935fcd8c6209da7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63616c63696e61692f6f61757468322d7865726f2f6d61737465722e737667)](https://travis-ci.org/calcinai/oauth2-xero)[![Total Downloads](https://camo.githubusercontent.com/83fd1704ec1c18b12ae8e0cfed53e53f4cc790442294875d770fd7e3a1894bc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63616c63696e61692f6f61757468322d7865726f2e737667)](https://packagist.org/packages/calcinai/oauth2-xero)

This package provides Xero OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

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

[](#installation)

To install, use composer:

```
$ composer require calcinai/oauth2-xero
```

Usage
-----

[](#usage)

Usage is the same as The League's OAuth client, using `\Calcinai\OAuth2\Client\Provider\Xero` as the provider.

### Authorization Code Flow

[](#authorization-code-flow)

```
session_start();

$provider = new \Calcinai\OAuth2\Client\Provider\Xero([
    'clientId'          => '{xero-client-id}',
    'clientSecret'      => '{xero-client-secret}',
    'redirectUri'       => 'https://example.com/callback-url',
]);

if (!isset($_GET['code'])) {

    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl([
        'scope' => 'openid email profile accounting.transactions'
    ]);

    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: ' . $authUrl);
    exit;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

    unset($_SESSION['oauth2state']);
    exit('Invalid state');

} else {

    // Try to get an access token (using the authorization code grant)
    $token = $provider->getAccessToken('authorization_code', [
        'code' => $_GET['code']
    ]);

    //If you added the openid/profile scopes you can access the authorizing user's identity.
    $identity = $provider->getResourceOwner($token);
    print_r($identity);

    //Get the tenants that this user is authorized to access
    $tenants = $provider->getTenants($token);
    print_r($tenants);
}
```

You can then store the token and use it to make requests against the api to the desired tenants

Scopes
------

[](#scopes)

OAuth scopes, indicating which parts of the Xero organisation you'd like your app to be able to access. The complete list of scopes can be found [here](https://developer.xero.com/documentation/oauth2/scopes).

```
$provider = new \Calcinai\OAuth2\Client\Provider\Xero([
   'clientId'          => '{xero-client-id}',
   'clientSecret'      => '{xero-client-secret}',
   'redirectUri'       => 'https://example.com/callback-url',
]);

$authUrl = $provider->$provider->getAuthorizationUrl([
   'scope' => 'bankfeeds accounting.transactions'
]);
```

Refreshing a token
------------------

[](#refreshing-a-token)

```
$newAccessToken = $provider->getAccessToken('refresh_token', [
    'refresh_token' => $existingAccessToken->getRefreshToken()
]);
```

Testing
-------

[](#testing)

```
$ ./vendor/bin/phpunit
```

Credits
-------

[](#credits)

- [All Contributors](https://github.com/calcinai/oauth2-xero/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/calcinai/oauth2-xero/blob/master/LICENSE) for more information.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance74

Regular maintenance activity

Popularity51

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 62.9% 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 ~158 days

Recently: every ~440 days

Total

15

Last Release

85d ago

Major Versions

v0.1.4 → v1.0.02020-02-19

PHP version history (3 changes)v0.1.0PHP &gt;=5.6.0

v1.0.2PHP &gt;=5.5.0

v1.2.0PHP &gt;=7.1.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2415868?v=4)[Michael Calcinai](/maintainers/calcinai)[@calcinai](https://github.com/calcinai)

---

Top Contributors

[![calcinai](https://avatars.githubusercontent.com/u/2415868?v=4)](https://github.com/calcinai "calcinai (22 commits)")[![davidwindell](https://avatars.githubusercontent.com/u/1720090?v=4)](https://github.com/davidwindell "davidwindell (3 commits)")[![pich](https://avatars.githubusercontent.com/u/549441?v=4)](https://github.com/pich "pich (2 commits)")[![hashnz](https://avatars.githubusercontent.com/u/2280579?v=4)](https://github.com/hashnz "hashnz (1 commits)")[![kylehqcom](https://avatars.githubusercontent.com/u/424321?v=4)](https://github.com/kylehqcom "kylehqcom (1 commits)")[![leereichardt](https://avatars.githubusercontent.com/u/1117892?v=4)](https://github.com/leereichardt "leereichardt (1 commits)")[![Rincewindrunner](https://avatars.githubusercontent.com/u/6251524?v=4)](https://github.com/Rincewindrunner "Rincewindrunner (1 commits)")[![srimanaravind](https://avatars.githubusercontent.com/u/4092725?v=4)](https://github.com/srimanaravind "srimanaravind (1 commits)")[![tobz-nz](https://avatars.githubusercontent.com/u/443054?v=4)](https://github.com/tobz-nz "tobz-nz (1 commits)")[![chris-ware](https://avatars.githubusercontent.com/u/19684457?v=4)](https://github.com/chris-ware "chris-ware (1 commits)")[![craig-mcmahon](https://avatars.githubusercontent.com/u/5879594?v=4)](https://github.com/craig-mcmahon "craig-mcmahon (1 commits)")

---

Tags

apiauthenticationauthorizationoauth2xeroAuthenticationSSOidentityoauthoauth2authorizationidpsingle sign onxeroxero api

### Embed Badge

![Health badge](/badges/calcinai-oauth2-xero/health.svg)

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

###  Alternatives

[adam-paterson/oauth2-slack

Slack OAuth 2.0 Client Provider for The PHP League OAuth2-Client

22694.8k5](/packages/adam-paterson-oauth2-slack)

PHPackages © 2026

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