tomas-kulhanek / oauth2-shoptet
Shoptet OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Installs: 225
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/tomas-kulhanek/oauth2-shoptet
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 Shoptet e-commerce platform.
Installation
composer require tomas-kulhanek/oauth2-shoptet
Usage
Authorization Code Flow
use TomasKulhanek\OAuth2\Shoptet\ShoptetProvider; $provider = new ShoptetProvider([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'redirectUri' => 'https://your-app.com/callback', 'eshopUrl' => 'https://your-eshop.myshoptet.com', ]); // 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->getEmail(); echo $owner->getName(); echo $owner->getProjectId(); echo $owner->getProjectUrl(); echo $owner->getProjectName();
Multi-tenant (dynamic eshop URL)
When each user provides their own eshop URL (e.g., from a login form):
$provider = new ShoptetProvider([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'redirectUri' => 'https://your-app.com/callback', 'eshopUrl' => $userProvidedEshopUrl, ]);
Or use withEshopUrl() to create a new provider instance with a different eshop URL:
$baseProvider = new ShoptetProvider([ 'clientId' => 'your-client-id', 'clientSecret' => 'your-client-secret', 'redirectUri' => 'https://your-app.com/callback', ]); $provider = $baseProvider->withEshopUrl('https://specific-eshop.myshoptet.com');
Shoptet OAuth Endpoints
All endpoints are relative to the eshop URL:
| Endpoint | URL |
|---|---|
| Authorization | {eshopUrl}/action/OAuthServer/authorize |
| Token | {eshopUrl}/action/OAuthServer/token |
| Resource | {eshopUrl}/action/OAuthServer/resource?method=getBasicEshop |
License
MIT