PHPackages                             e-lodgy/oauth2-bookingsync-php - 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. e-lodgy/oauth2-bookingsync-php

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

e-lodgy/oauth2-bookingsync-php
==============================

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

v0.8.1(2y ago)06[1 issues](https://github.com/e-lodgy/oauth2-bookingsync-php/issues)[3 PRs](https://github.com/e-lodgy/oauth2-bookingsync-php/pulls)MITPHPPHP ^7.4|^8.0CI failing

Since Jun 5Pushed 1mo ago1 watchersCompare

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

READMEChangelog (6)Dependencies (6)Versions (19)Used By (0)

BookingSync Provider for OAuth 2.0 Client
=========================================

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

[![Latest Version](https://camo.githubusercontent.com/7746ef88fea95bd34aa40f70014536bbed318eb40315ae92a2ff4e73db9b9180/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f426f6f6b696e6753796e632f6f61757468322d626f6f6b696e6773796e632d7068702e7376673f7374796c653d666c61742d737175617265)](https://github.com/bookingsync/oauth2-bookingsync-php/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/42f7bc1b4022a6d0fa3a6e69ca989f063bc449fa5272792ba242a12b1a309721/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f426f6f6b696e6753796e632f6f61757468322d626f6f6b696e6773796e632d7068702f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/bookingsync/oauth2-bookingsync-php)[![Coverage Status](https://camo.githubusercontent.com/71e2bb5ae137d0d551f65ec7f7cb69030928f7a67a6c0ec4cd56c8825fdefe24/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f626f6f6b696e6773796e632f6f61757468322d626f6f6b696e6773796e632d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bookingsync/oauth2-bookingsync-php/code-structure)[![Quality Score](https://camo.githubusercontent.com/acc5a6a0ee76b6f778aeb7ae926c182e4c3a5385f65655750307582913fc6ee5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f626f6f6b696e6773796e632f6f61757468322d626f6f6b696e6773796e632d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bookingsync/oauth2-bookingsync-php)[![Total Downloads](https://camo.githubusercontent.com/e4fe385a4615bb8c924e1b1a8c04b7f76d1ddd105545a2316ced3f5e6c242d9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f6f6b696e6773796e632f6f61757468322d626f6f6b696e6773796e632d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bookingsync/oauth2-bookingsync-php)

This package provides BookingSync 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 bookingsync/oauth2-bookingsync-php

```

Usage
-----

[](#usage)

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

### Authorization Code Flow

[](#authorization-code-flow)

```
use Bookingsync\OAuth2\Client\Provider\BookingSyncProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;

$provider = new BookingSyncProvider([
    'clientId'          => 'XXXXXXXX',
    'clientSecret'      => 'XXXXXXXX',
    'redirectUri'       => 'https://www.example.com/callback-url', // https is mandatory for BookingSync
    'scopes'            => ['public'] // scopes required by your BookingSync application.
]);

if (! isset($_GET['code'])) {
    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_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']
    ]);

    // Optional: Now you have a token you can look up a users profile data
    try {
        // Using the access token, we may look up details about the resource owner.
        $resourceOwner = $provider->getResourceOwner($accessToken);

        // Use these details to create a new profile
        printf('Hello %s!', $resourceOwner->getBusinessName());

    } catch (IdentityProviderException $e) {
        // Failed to get user details
        exit($e->getMessage());
    }

    // Use this to interact with an API on the users behalf
    echo $token->getAccessToken();

    // Use this to get a new access token if the old one expires
    echo $token->getRefreshToken();

    // Unix timestamp of when the token will expire, and need refreshing
    echo $token->getExpires();
}
```

### Refreshing a Token

[](#refreshing-a-token)

```
use Bookingsync\OAuth2\Client\Provider\BookingSyncProvider;
use League\OAuth2\Client\Grant\RefreshToken;
use League\OAuth2\Client\Token\AccessTokenInterface;

$provider = new BookingSyncProvider([
    'clientId'          => 'XXXXXXXX',
    'clientSecret'      => 'XXXXXXXX',
    'redirectUri'       => 'https://example.com/callback-url'
]);

/** @var AccessTokenInterface $existingAccessToken */
$existingAccessToken = getAccessTokenFromYourDataStore();

if ($existingAccessToken->hasExpired()) {
    $grant = new RefreshToken();
    $token = $provider->getAccessToken($grant, ['refresh_token' => $existingAccessToken->getRefreshToken()]);
}
```

### Client Credentials

[](#client-credentials)

```
use Bookingsync\OAuth2\Client\Provider\BookingSyncProvider;
use League\OAuth2\Client\Grant\ClientCredentials;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;

$provider = new BookingSyncProvider([
    'clientId'          => 'XXXXXXXX',
    'clientSecret'      => 'XXXXXXXX',
    'redirectUri'       => 'https://example.com/callback-url'
]);

try {
    // Try to get an access token using the client credentials grant.
    $grant = new ClientCredentials();
    $accessToken = $provider->getAccessToken($grant);
} catch (IdentityProviderException $e) {
    // Failed to get the access token
    exit($e->getMessage());
}
```

Testing
-------

[](#testing)

```
vendor/bin/phpunit

```

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance61

Regular maintenance activity

Popularity4

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 68.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 ~266 days

Recently: every ~209 days

Total

13

Last Release

800d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.4.0

v0.4.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce2276bdc3eeb394bfbb7aa55f92e43ab708da844a860d52b4740887ce597841?d=identicon)[benjaminmal](/maintainers/benjaminmal)

---

Top Contributors

[![benjaminmal](https://avatars.githubusercontent.com/u/58468686?v=4)](https://github.com/benjaminmal "benjaminmal (73 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (22 commits)")[![ZenCocoon](https://avatars.githubusercontent.com/u/10502?v=4)](https://github.com/ZenCocoon "ZenCocoon (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![JulienItard](https://avatars.githubusercontent.com/u/1370893?v=4)](https://github.com/JulienItard "JulienItard (1 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (1 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationbookingsync

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/e-lodgy-oauth2-bookingsync-php/health.svg)

```
[![Health](https://phpackages.com/badges/e-lodgy-oauth2-bookingsync-php/health.svg)](https://phpackages.com/packages/e-lodgy-oauth2-bookingsync-php)
```

###  Alternatives

[stevenmaguire/oauth2-keycloak

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

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

251.7M1](/packages/mollie-oauth2-mollie-php)[omines/oauth2-gitlab

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

36721.5k13](/packages/omines-oauth2-gitlab)

PHPackages © 2026

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