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

v1.0.0 2026-02-20 22:48 UTC

This package is auto-updated.

Last update: 2026-02-20 22:50:29 UTC


README

PHP Version License

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