compwright/oauth2-quickbooks-online

为PHP League OAuth2-Client提供的Quickbooks Online OAuth 2.0客户端提供程序

v1.0.1 2023-12-13 19:39 UTC

This package is auto-updated.

Last update: 2024-09-13 21:12:34 UTC


README

Latest Version Build Status Total Downloads

本包为PHP League的OAuth 2.0客户端提供Quickbooks Online OAuth 2.0支持。

安装

安装时请使用composer

composer require compwright/oauth2-quickbooks-online league/oauth2-client

使用方法

使用方法与The League的OAuth客户端相同,使用\Compwright\OAuth2_Quickbooks_Online\Provider作为提供者。

示例:授权码流

$provider = new Compwright\OAuth2_Quickbooks_Online\Provider([
    'clientId'      => '{quickbooks-online-client-id}',
    'clientSecret'  => '{quickbooks-online-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->getState();
    header('Location: ' . $authUrl);
    exit;
}

// Check given state against previously stored one to mitigate CSRF attack
if (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
    unset($_SESSION['oauth2state']);
    exit('Invalid state');
}

// Get an access token using the authorization code grant
$token = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code'],
    'state' => $_GET['state'],
    'realmId' => $_GET['realmId'], // required for getResourceOwner() to work
]);

// You can look up a users profile data
$user = $provider->getResourceOwner($token);
printf('Hello %s!', $user->getId());

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

测试

$ make test

贡献

有关详细信息,请参阅CONTRIBUTING

鸣谢

此包是从chadhutchins/oauth2-quickbooks分叉而来,截至2023年12月似乎已被遗弃。

许可协议

MIT许可协议(MIT)。有关更多信息,请参阅许可文件