tomas-kulhanek / oauth2-fakturoid
Fakturoid OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tomas-kulhanek/oauth2-fakturoid
Requires
- php: >=8.4
- league/oauth2-client: ^2.7
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5
- rector/rector: ^2.3
- shipmonk/phpstan-rules: ^4.3
- slevomat/coding-standard: ^8.27
- squizlabs/php_codesniffer: ^4.0
README
League OAuth2 Client provider for Fakturoid invoicing platform.
Installation
composer require tomas-kulhanek/oauth2-fakturoid
Usage
Authorization Code Flow
use TomasKulhanek\OAuth2\Fakturoid\FakturoidProvider; $provider = new FakturoidProvider([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'redirectUri' => 'https://your-app.com/callback', ]); // Step 1: Redirect to authorization $authUrl = $provider->getAuthorizationUrl(); $_SESSION['oauth2state'] = $provider->getState(); header('Location: ' . $authUrl); exit; // Step 2: Handle callback if ($_GET['state'] !== $_SESSION['oauth2state']) { exit('Invalid state'); } $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'], ]); // Step 3: Get resource owner $owner = $provider->getResourceOwner($token); echo $owner->getId(); echo $owner->getFullName(); echo $owner->getEmail(); echo $owner->getAvatarUrl(); echo $owner->getDefaultAccount();
Client Credentials Flow
$token = $provider->getAccessToken('client_credentials');
Refreshing a Token
$newToken = $provider->getAccessToken('refresh_token', [ 'refresh_token' => $existingToken->getRefreshToken(), ]);
Accessing Accounts
The resource owner provides access to all Fakturoid accounts the user can manage:
$owner = $provider->getResourceOwner($token); foreach ($owner->getAccounts() as $account) { echo $account['slug']; // Account URL identifier echo $account['name']; // Account name echo $account['permission']; // 'owner', 'accountant', etc. echo $account['registration_no'];// Registration number }
Fakturoid OAuth Endpoints
| Endpoint | URL |
|---|---|
| Authorization | https://app.fakturoid.cz/api/v3/oauth |
| Token | https://app.fakturoid.cz/api/v3/oauth/token |
| User Info | https://app.fakturoid.cz/api/v3/user.json |
License
MIT