forked from web-com-pl/amazon-selling-partner-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth.php
28 lines (22 loc) · 1010 Bytes
/
oauth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
use Ramsey\Uuid\Uuid;
use Webcom\Amazon\Rest\AmazonTransportClient;
use Webcom\Amazon\Rest\ApiException;
use Webcom\Amazon\Rest\AuthorizationApi\Api\AuthorizationApi;
use Webcom\Amazon\Rest\CredentialsContainer;
use Webcom\Amazon\Rest\EndpointLocator;
include_once __DIR__ . '/../vendor/autoload.php';
session_start();
try {
// Your config stuff (get example from config-example.json)
$config = json_decode(file_get_contents(__DIR__ . '/../config.json'), true);
$endpoint = EndpointLocator::resolveByMarketplaceId($config['marketplace']);
$credentials = new CredentialsContainer($endpoint, true);
$credentials->setAppId($config['appId']);
$api = new AuthorizationApi(new AmazonTransportClient(), $credentials);
$_SESSION['token'] = Uuid::uuid4();
dump('Authorize app');// $config['redirectUri']
echo '<a href="' . $api->getOauthUri($config['redirectUri'], $_SESSION['token']) . '">Login via Amazon</a>';
} catch (ApiException $e) {
dump($e->getMessage());
}