- Getting Started
- Obtaining OAuth Tokens For Patrons
- Patreon Integration Examples
- Method Documentation
- Library Architecture
Patreon implements the standard OAuth 2.0 login flow which is compatible with any standards compliant OAuth 2.0 Client, including The League of Extraordinary Packages OAuth 2.0 Client and Laravel Socialite.
OAuth 2.0 Patreon PHP includes a simple Patreon OAuth Client which you can use to accept user logins.
- A user visits your login page
- You redirect the user to the Patreon login page
- The user is asked the user to confirm that they authorise your application
- Patreon redirects the user back to your
redirect_uri
with acode
query parameter - You make a request to Patreon exchanging the
code
for anaccess_token
andrefresh_token
After you have obtained the access token you are able to communicate with the Patreon API on behalf of the user. You should store the user's access token and refresh token in your database.
require_once 'vendor/autoload.php';
use Squid\Patreon\OAuth;
use Squid\Patreon\Patreon;
$oauth = new OAuth(
'client_id',
'client_secret',
'redirect_uri'
);
if (! isset($_GET['code'])) {
Header('Location: ' . $oauth2->getAuthorizationUrl());
exit;
}
$tokens = $oauth->getAccessToken($_GET['code']);
$patreon = new Patreon($tokens['access_token']);
$user = $patreon->me()->get();
echo "Hello, {$user->full_name}!";
if ($user->hasActivePledge()) {
echo "You are a patron of my campaign, thank you!";
} else {
echo "You are not a patron of my campaign.";
}