Connect OAuth Flow Example (PHP)
This example demonstrates a bare-bones PHP implementation of the OAuth flow for Square APIs. It serves a link that directs merchants to the OAuth Permissions form and handles the result of the authorization, which is sent to your application's Redirect URL (specified on the application dashboard).
For more information, see OAuth Overview, along with the comments included in
Download Composer and Unirest
This application requires the Unirest HTTP library for PHP, which you install via Composer.
First, download Composer in this directory with the instructions on this page.
After you've downloaded Composer, install the Unirest dependency with the following command from this directory:
php composer.phar install
Specify your application credentials
In order for the sample to work, you must specify fields in
In both files, replace the value of
$application_idwith your application's ID, available on your application dashboard.
callback.php, replace the value of
$applicationSecretwith your application's secret, also available on your application dashboard.
Set your application's Redirect URL
On your application dashboard, set your application's Redirect URL to
Note that applications that don't use a
localhost URL must use HTTPS. HTTP is
localhost URLs to simplify the development process.
Running the example
To run the example, execute the following from the directory that contains these files:
php -S localhost:8000
You can then proceed through the OAuth flow by visiting
in your web browser.