PHPackages                             wheniwork/oauth2-square - 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. wheniwork/oauth2-square

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

wheniwork/oauth2-square
=======================

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

v1.3.0(10y ago)193.2k4MITPHPPHP &gt;=5.4.0

Since Feb 23Pushed 2y ago27 watchersCompare

[ Source](https://github.com/wheniwork/oauth2-square)[ Packagist](https://packagist.org/packages/wheniwork/oauth2-square)[ RSS](/packages/wheniwork-oauth2-square/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (16)Used By (0)

Square Provider for OAuth 2.0 Client
====================================

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

[![Build Status](https://camo.githubusercontent.com/e592f7a7126bbed33d06ce91e3ea675a424f955c118d4970cb234588253a6d29/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7768656e69776f726b2f6f61757468322d7371756172652e737667)](https://travis-ci.org/wheniwork/oauth2-square)[![Code Coverage](https://camo.githubusercontent.com/543be2adcbedffd1f41f2aafb5a8cce6b759ad97c6df4b24b407a7d6837d4a28/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f7768656e69776f726b2f6f61757468322d7371756172652e737667)](https://coveralls.io/r/wheniwork/oauth2-square)[![Code Quality](https://camo.githubusercontent.com/1e4d562796e472e1534ed515190e7e6d422055284a59131a8960da6f8e82a647/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7768656e69776f726b2f6f61757468322d7371756172652e737667)](https://scrutinizer-ci.com/g/wheniwork/oauth2-square/)[![License](https://camo.githubusercontent.com/ee0b7498e5264a470e65077dc723d3f1f1c16dbddec561cf6cb7f850bbab1c09/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7768656e69776f726b2f6f61757468322d7371756172652e737667)](https://github.com/wheniwork/oauth2-square/blob/master/LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/4ce6a1d7fa45c99c8e73218b28e4f3cf87d14dc0ed7bd7fc7d8f4e66d22f49ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7768656e69776f726b2f6f61757468322d7371756172652e737667)](https://packagist.org/packages/wheniwork/oauth2-square)

This package provides Square 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 wheniwork/oauth2-square

```

Usage
-----

[](#usage)

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

To make requests against the Square staging server, pass `'debug' => true` as part of the initial configuration options.

### Authorization Code Flow

[](#authorization-code-flow)

```
$provider = new Wheniwork\OAuth2\Client\Provider\Square([
    'clientId'          => '{square-client-id}',
    'clientSecret'      => '{square-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();
    $_SESSION['oauth2state'] = $provider->state;
    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 {

        // We got an access token, let's now get the user's details
        $userDetails = $provider->getUserDetails($token);

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

    } catch (Exception $e) {

        // Failed to get user details
        exit('Oh dear...');
    }

    // Use this to interact with an API on the users behalf
    echo $token->accessToken;
}
```

Refreshing a Token
------------------

[](#refreshing-a-token)

Square does not provide refresh tokens. Instead, an access token can be "renewed" up to 15 days after it expires. To accomdate this, the Square provider provides an additional grant, `RenewToken`.

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

$token = $provider->getAccessToken('renew_token', ['access_token' => $accessToken]);
```

This grant can also be used by injecting the `AccessToken` instance directly, instead of providing a parameter to `getAccessToken`:

```
$grant = new Wheniwork\OAuth2\Client\Grant\RenewToken($token);
$token = $provider->getAccessToken($grant);
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~34 days

Recently: every ~77 days

Total

13

Last Release

3733d ago

Major Versions

v0.2.0 → v1.0.02015-02-24

v1.2.4 → v2.0.0-beta12015-08-05

### Community

Maintainers

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

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

---

Top Contributors

[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (27 commits)")[![ameech](https://avatars.githubusercontent.com/u/831646?v=4)](https://github.com/ameech "ameech (1 commits)")

---

Tags

clientoauthoauth2authorizationauthorisationsquare

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wheniwork-oauth2-square/health.svg)

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

###  Alternatives

[stevenmaguire/oauth2-keycloak

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

2306.4M45](/packages/stevenmaguire-oauth2-keycloak)[patrickbussmann/oauth2-apple

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

1152.8M12](/packages/patrickbussmann-oauth2-apple)[omines/oauth2-gitlab

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

36779.2k16](/packages/omines-oauth2-gitlab)[league/oauth2-instagram

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

661.1M48](/packages/league-oauth2-instagram)[mollie/oauth2-mollie-php

Mollie Provider for OAuth 2.0 Client

261.8M1](/packages/mollie-oauth2-mollie-php)[dalpras/oauth2-gotowebinar

LogMeIn GoToWebinar OAuth 2.0 Client Provider for the PHP League's OAuth 2.0 Client

1246.3k](/packages/dalpras-oauth2-gotowebinar)

PHPackages © 2026

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