{"id":44310738,"url":"https://github.com/wheniwork/oauth2-square","last_synced_at":"2026-02-11T04:07:03.373Z","repository":{"id":27704920,"uuid":"31191793","full_name":"wheniwork/oauth2-square","owner":"wheniwork","description":"Square provider for the OAuth 2.0 Client","archived":false,"fork":false,"pushed_at":"2024-04-16T12:50:21.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-03T22:24:59.143Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wheniwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-23T02:55:57.000Z","updated_at":"2025-02-16T03:42:15.000Z","dependencies_parsed_at":"2022-09-03T03:36:14.219Z","dependency_job_id":null,"html_url":"https://github.com/wheniwork/oauth2-square","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/wheniwork/oauth2-square","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wheniwork%2Foauth2-square","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wheniwork%2Foauth2-square/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wheniwork%2Foauth2-square/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wheniwork%2Foauth2-square/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wheniwork","download_url":"https://codeload.github.com/wheniwork/oauth2-square/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wheniwork%2Foauth2-square/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29326957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-11T04:07:02.055Z","updated_at":"2026-02-11T04:07:03.366Z","avatar_url":"https://github.com/wheniwork.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Square Provider for OAuth 2.0 Client\n\n[![Build Status](https://img.shields.io/travis/wheniwork/oauth2-square.svg)](https://travis-ci.org/wheniwork/oauth2-square)\n[![Code Coverage](https://img.shields.io/coveralls/wheniwork/oauth2-square.svg)](https://coveralls.io/r/wheniwork/oauth2-square)\n[![Code Quality](https://img.shields.io/scrutinizer/g/wheniwork/oauth2-square.svg)](https://scrutinizer-ci.com/g/wheniwork/oauth2-square/)\n[![License](https://img.shields.io/packagist/l/wheniwork/oauth2-square.svg)](https://github.com/wheniwork/oauth2-square/blob/master/LICENSE)\n[![Latest Stable Version](https://img.shields.io/packagist/v/wheniwork/oauth2-square.svg)](https://packagist.org/packages/wheniwork/oauth2-square)\n\nThis package provides Square OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).\n\n## Installation\n\nTo install, use composer:\n\n```\ncomposer require wheniwork/oauth2-square\n```\n\n## Usage\n\nUsage is the same as The League's OAuth client, using `Wheniwork\\OAuth2\\Client\\Provider\\Square` as the provider.\n\nTo make requests against the Square staging server, pass `'debug' =\u003e true` as part of the initial configuration options.\n\n### Authorization Code Flow\n\n```php\n$provider = new Wheniwork\\OAuth2\\Client\\Provider\\Square([\n    'clientId'          =\u003e '{square-client-id}',\n    'clientSecret'      =\u003e '{square-client-secret}',\n    'redirectUri'       =\u003e 'https://example.com/callback-url'\n]);\n\nif (!isset($_GET['code'])) {\n\n    // If we don't have an authorization code then get one\n    $authUrl = $provider-\u003egetAuthorizationUrl();\n    $_SESSION['oauth2state'] = $provider-\u003estate;\n    header('Location: '.$authUrl);\n    exit;\n\n// Check given state against previously stored one to mitigate CSRF attack\n} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {\n\n    unset($_SESSION['oauth2state']);\n    exit('Invalid state');\n\n} else {\n\n    // Try to get an access token (using the authorization code grant)\n    $token = $provider-\u003egetAccessToken('authorization_code', [\n        'code' =\u003e $_GET['code']\n    ]);\n\n    // Optional: Now you have a token you can look up a users profile data\n    try {\n\n        // We got an access token, let's now get the user's details\n        $userDetails = $provider-\u003egetUserDetails($token);\n\n        // Use these details to create a new profile\n        printf('Hello %s!', $userDetails-\u003efirstName);\n\n    } catch (Exception $e) {\n\n        // Failed to get user details\n        exit('Oh dear...');\n    }\n\n    // Use this to interact with an API on the users behalf\n    echo $token-\u003eaccessToken;\n}\n```\n\n## Refreshing a Token\n\nSquare does not provide refresh tokens. Instead, an access token can be \"renewed\"\nup to 15 days after it expires. To accomdate this, the Square provider provides\nan additional grant, `RenewToken`.\n\n```php\n$provider = new Wheniwork\\OAuth2\\Client\\Provider\\Square([\n    'clientId'          =\u003e '{square-client-id}',\n    'clientSecret'      =\u003e '{square-client-secret}',\n    'redirectUri'       =\u003e 'https://example.com/callback-url'\n]);\n\n$token = $provider-\u003egetAccessToken('renew_token', ['access_token' =\u003e $accessToken]);\n```\n\nThis grant can also be used by injecting the `AccessToken` instance directly,\ninstead of providing a parameter to `getAccessToken`:\n\n```php\n$grant = new Wheniwork\\OAuth2\\Client\\Grant\\RenewToken($token);\n$token = $provider-\u003egetAccessToken($grant);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwheniwork%2Foauth2-square","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwheniwork%2Foauth2-square","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwheniwork%2Foauth2-square/lists"}