Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2016 Gabriel Jean
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+37
View File
@@ -0,0 +1,37 @@
# Etsy Provider for OAuth 1.0 Client
[![Latest Stable Version](https://img.shields.io/packagist/v/y0lk/oauth1-etsy.svg)](https://packagist.org/packages/y0lk/oauth1-etsy)
[![Build Status](https://img.shields.io/travis/Y0lk/oauth1-etsy.svg)](https://travis-ci.org/Y0lk/oauth1-etsy)
[![License](https://img.shields.io/packagist/l/y0lk/oauth1-etsy.svg)](https://github.com/y0lk/oauth1-etsy/blob/master/LICENSE)
[![Total Downloads](https://img.shields.io/packagist/dt/y0lk/oauth1-etsy.svg?maxAge=2592000)](https://packagist.org/packages/y0lk/oauth1-etsy)
This package provides Etsy API OAuth 1.0 support for the PHP League's [OAuth 1.0 Client](https://github.com/thephpleague/oauth1-client).
## Installation
Via Composer
```shell
$ composer require y0lk/oauth1-etsy
```
## Usage
Usage is the same as The League's OAuth client, using `Y0lk\OAuth1\Client\Server\Etsy` as the provider.
```php
$server = new Y0lk\OAuth1\Client\Server\Etsy([
'identifier' => 'your-client-id',
'secret' => 'your-client-secret',
'scope' => '', //See Etsy documentation for the full list of permission scopes
'callback_uri' => 'http://callback.url/callback'
]);
```
### Permission Scopes
See the Etsy documentation for [Permission Scopes](https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes)
## License
The MIT License (MIT). Please see [License File](https://github.com/thephpleague/oauth1-client/blob/master/LICENSE) for more information.
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
stopOnFailure="false"
bootstrap="./vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
<testsuites>
<testsuite name="common">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
+192
View File
@@ -0,0 +1,192 @@
<?php
namespace Y0lk\OAuth1\Client\Server;
use League\OAuth1\Client\Credentials\TokenCredentials;
use League\OAuth1\Client\Server\Server;
use League\OAuth1\Client\Server\User;
class Etsy extends Server
{
const API_URL = 'https://openapi.etsy.com/v2/';
/**
* Application scope.
*
* @var string
*/
protected $applicationScope = "";
/**
* Login url for authorization provided by Etsy
* @var string
*/
protected $login_url = "";
/**
* {@inheritDoc}
*/
public function __construct($clientCredentials, SignatureInterface $signature = null)
{
parent::__construct($clientCredentials, $signature);
if (is_array($clientCredentials)) {
$this->parseConfiguration($clientCredentials);
}
}
/**
* Set the application scope.
*
* @param string $applicationScope
*
* @return Etsy
*/
public function setApplicationScope($applicationScope)
{
$this->applicationScope = $applicationScope;
return $this;
}
/**
* Get application scope.
*
* @return string
*/
public function getApplicationScope()
{
return $this->applicationScope;
}
/**
* {@inheritDoc}
*/
public function urlTemporaryCredentials()
{
return self::API_URL.'oauth/request_token?scope='.$this->applicationScope;
}
/**
* {@inheritDoc}
*/
public function urlAuthorization()
{
return $this->login_url;
}
/**
* {@inheritDoc}
*/
public function urlTokenCredentials()
{
return self::API_URL.'oauth/access_token';
}
/**
* {@inheritDoc}
*/
public function urlUserDetails()
{
return self::API_URL.'users/__SELF__';
}
/**
* {@inheritDoc}
*/
public function userDetails($data, TokenCredentials $tokenCredentials)
{
$data = $data['results'][0];
$user = new User();
$user->uid = $data['user_id'];
$user->nickname = $data['login_name'];
$used = array('user_id', 'login_name');
// Save all extra data
$user->extra = array_diff_key($data, array_flip($used));
return $user;
}
/**
* {@inheritDoc}
*/
public function userUid($data, TokenCredentials $tokenCredentials)
{
return $data['user']['user_id'];
}
/**
* {@inheritDoc}
*/
public function userEmail($data, TokenCredentials $tokenCredentials)
{
return;
}
/**
* {@inheritDoc}
*/
public function userScreenName($data, TokenCredentials $tokenCredentials)
{
return $data['user']['login_name'];
}
/**
* Parse configuration array to set attributes.
*
* @param array $configuration
*/
private function parseConfiguration(array $configuration = array())
{
$configToPropertyMap = array(
'scope' => 'applicationScope'
);
foreach ($configToPropertyMap as $config => $property) {
if (isset($configuration[$config])) {
$this->$property = $configuration[$config];
}
}
}
/**
* {@inheritDoc}
*/
public function getTemporaryCredentials()
{
$uri = $this->urlTemporaryCredentials();
$client = $this->createHttpClient();
$header = $this->temporaryCredentialsProtocolHeader($uri);
$authorizationHeader = array('Authorization' => $header);
$headers = $this->buildHttpClientHeaders($authorizationHeader);
try {
$response = $client->post($uri, [
'headers' => $headers
]);
} catch (BadResponseException $e) {
return $this->handleTemporaryCredentialsBadResponse($e);
}
//Catch body and retrieve Etsy login_url
$body = $response->getBody();
parse_str($body, $data);
$this->login_url = $data['login_url'];
return $this->createTemporaryCredentials($response->getBody());
}
/**
* {@inheritDoc}
*/
public function getAuthorizationUrl($temporaryIdentifier, array $options = [])
{
// Somebody can pass through an instance of temporary
// credentials and we'll extract the identifier from there.
if ($temporaryIdentifier instanceof TemporaryCredentials) {
$temporaryIdentifier = $temporaryIdentifier->getIdentifier();
}
//Return the authorization url directly since it's provided by Etsy and contains all parameters
return $this->urlAuthorization();
}
}