-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/34741_account_api (pull request #147)
Feature/34741 account api Approved-by: Martin Beckmann Approved-by: Andre Moelle
- Loading branch information
Showing
102 changed files
with
4,961 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
|
||
namespace Mediaopt\DHL\Api; | ||
|
||
class Authentication | ||
{ | ||
const DEFAULT_GRANT_TYPE = 'password'; | ||
|
||
/** | ||
* @param Authentication\Client $client | ||
* @param Credentials $credentials | ||
* @param Credentials $userPass | ||
* @return string | ||
*/ | ||
public static function getToken(Authentication\Client $client, Credentials $credentials, Credentials $userPass): string | ||
{ | ||
$tokenPostBody = new Authentication\Model\TokenPostBody(); | ||
$tokenPostBody->setClientId($credentials->getUsername()); | ||
$tokenPostBody->setClientSecret($credentials->getPassword()); | ||
$tokenPostBody->setUsername($userPass->getUsername()); | ||
$tokenPostBody->setPassword($userPass->getPassword()); | ||
$tokenPostBody->setGrantType(self::DEFAULT_GRANT_TYPE); | ||
|
||
$token = $client->dispenseToken($tokenPostBody); | ||
|
||
return $token->getAccessToken(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/modules/mo/mo_dhl/Api/Authentication/Authentication/ApiKeyAuthentication.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Mediaopt\DHL\Api\Authentication\Authentication; | ||
|
||
class ApiKeyAuthentication implements \Jane\Component\OpenApiRuntime\Client\AuthenticationPlugin | ||
{ | ||
private $apiKey; | ||
public function __construct(string $apiKey) | ||
{ | ||
$this->{'apiKey'} = $apiKey; | ||
} | ||
public function authentication(\Psr\Http\Message\RequestInterface $request) : \Psr\Http\Message\RequestInterface | ||
{ | ||
$request = $request->withHeader('dhl-api-key', $this->{'apiKey'}); | ||
return $request; | ||
} | ||
public function getScope() : string | ||
{ | ||
return 'apiKey'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/modules/mo/mo_dhl/Api/Authentication/Authentication/BasicAuthAuthentication.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Mediaopt\DHL\Api\Authentication\Authentication; | ||
|
||
class BasicAuthAuthentication implements \Jane\Component\OpenApiRuntime\Client\AuthenticationPlugin | ||
{ | ||
private $username; | ||
private $password; | ||
public function __construct(string $username, string $password) | ||
{ | ||
$this->{'username'} = $username; | ||
$this->{'password'} = $password; | ||
} | ||
public function authentication(\Psr\Http\Message\RequestInterface $request) : \Psr\Http\Message\RequestInterface | ||
{ | ||
$header = sprintf('Basic %s', base64_encode(sprintf('%s:%s', $this->{'username'}, $this->{'password'}))); | ||
$request = $request->withHeader('Authorization', $header); | ||
return $request; | ||
} | ||
public function getScope() : string | ||
{ | ||
return 'basicAuth'; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/modules/mo/mo_dhl/Api/Authentication/Authentication/BearerAuthAuthentication.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Mediaopt\DHL\Api\Authentication\Authentication; | ||
|
||
class BearerAuthAuthentication implements \Jane\Component\OpenApiRuntime\Client\AuthenticationPlugin | ||
{ | ||
private $token; | ||
public function __construct(string $token) | ||
{ | ||
$this->{'token'} = $token; | ||
} | ||
public function authentication(\Psr\Http\Message\RequestInterface $request) : \Psr\Http\Message\RequestInterface | ||
{ | ||
$header = sprintf('Bearer %s', $this->{'token'}); | ||
$request = $request->withHeader('Authorization', $header); | ||
return $request; | ||
} | ||
public function getScope() : string | ||
{ | ||
return 'bearerAuth'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Mediaopt\DHL\Api\Authentication; | ||
|
||
class Client extends \Mediaopt\DHL\Api\Authentication\Runtime\Client\Client | ||
{ | ||
/** | ||
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE) | ||
* | ||
* @return null|\Mediaopt\DHL\Api\Authentication\Model\GetResponse200|\Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function get(string $fetch = self::FETCH_OBJECT) | ||
{ | ||
return $this->executeEndpoint(new \Mediaopt\DHL\Api\Authentication\Endpoint\Get(), $fetch); | ||
} | ||
/** | ||
* The client makes a request to the token endpoint by adding the following parameters | ||
using the application/x-www-form-urlencoded format with a character | ||
encoding of UTF-8 in the HTTP request entity-body: | ||
* grant_type __REQUIRED__. Must be set to "password" or "refresh_token". | ||
* client_id __REQUIRED__ (aka client_id (api key)) | ||
* client_secret __REQUIRED__ (aka client_secret) | ||
Depending on the grant_type, __additional parameters__ must be provided: | ||
<h3>grant_type=password</h3> | ||
This currently is the only grant type supported. | ||
* username __REQUIRED__. The resource owner username. Aka username for business customer portal | ||
* password __REQUIRED__. The resource owner password. Aka password for business customer portal | ||
* | ||
* @param \Mediaopt\DHL\Api\Authentication\Model\TokenPostBody $requestBody | ||
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE) | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenBadRequestException | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenUnauthorizedException | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenForbiddenException | ||
* | ||
* @return null|\Mediaopt\DHL\Api\Authentication\Model\TokenResponse|\Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function dispenseToken(\Mediaopt\DHL\Api\Authentication\Model\TokenPostBody $requestBody, string $fetch = self::FETCH_OBJECT) | ||
{ | ||
return $this->executeEndpoint(new \Mediaopt\DHL\Api\Authentication\Endpoint\DispenseToken($requestBody), $fetch); | ||
} | ||
/** | ||
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE) | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\HelloBadRequestException | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\HelloUnauthorizedException | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\HelloForbiddenException | ||
* | ||
* @return null|\Mediaopt\DHL\Api\Authentication\Model\TokenResponse|\Psr\Http\Message\ResponseInterface | ||
*/ | ||
public function hello(string $fetch = self::FETCH_OBJECT) | ||
{ | ||
return $this->executeEndpoint(new \Mediaopt\DHL\Api\Authentication\Endpoint\Hello(), $fetch); | ||
} | ||
public static function create($httpClient = null, array $additionalPlugins = array(), array $additionalNormalizers = array()) | ||
{ | ||
if (null === $httpClient) { | ||
$httpClient = \Http\Discovery\Psr18ClientDiscovery::find(); | ||
$plugins = array(); | ||
$uri = \Http\Discovery\Psr17FactoryDiscovery::findUrlFactory()->createUri('https://api-eu.dhl.com/parcel/de/account/auth/ropc/v1'); | ||
$plugins[] = new \Http\Client\Common\Plugin\AddHostPlugin($uri); | ||
$plugins[] = new \Http\Client\Common\Plugin\AddPathPlugin($uri); | ||
if (count($additionalPlugins) > 0) { | ||
$plugins = array_merge($plugins, $additionalPlugins); | ||
} | ||
$httpClient = new \Http\Client\Common\PluginClient($httpClient, $plugins); | ||
} | ||
$requestFactory = \Http\Discovery\Psr17FactoryDiscovery::findRequestFactory(); | ||
$streamFactory = \Http\Discovery\Psr17FactoryDiscovery::findStreamFactory(); | ||
$normalizers = array(new \Symfony\Component\Serializer\Normalizer\ArrayDenormalizer(), new \Mediaopt\DHL\Api\Authentication\Normalizer\JaneObjectNormalizer()); | ||
if (count($additionalNormalizers) > 0) { | ||
$normalizers = array_merge($normalizers, $additionalNormalizers); | ||
} | ||
$serializer = new \Symfony\Component\Serializer\Serializer($normalizers, array(new \Symfony\Component\Serializer\Encoder\JsonEncoder(new \Symfony\Component\Serializer\Encoder\JsonEncode(), new \Symfony\Component\Serializer\Encoder\JsonDecode(array('json_decode_associative' => true))))); | ||
return new static($httpClient, $requestFactory, $serializer, $streamFactory); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/modules/mo/mo_dhl/Api/Authentication/Endpoint/DispenseToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Mediaopt\DHL\Api\Authentication\Endpoint; | ||
|
||
class DispenseToken extends \Mediaopt\DHL\Api\Authentication\Runtime\Client\BaseEndpoint implements \Mediaopt\DHL\Api\Authentication\Runtime\Client\Endpoint | ||
{ | ||
/** | ||
* The client makes a request to the token endpoint by adding the following parameters | ||
using the application/x-www-form-urlencoded format with a character | ||
encoding of UTF-8 in the HTTP request entity-body: | ||
* grant_type __REQUIRED__. Must be set to "password" or "refresh_token". | ||
* client_id __REQUIRED__ (aka client_id (api key)) | ||
* client_secret __REQUIRED__ (aka client_secret) | ||
Depending on the grant_type, __additional parameters__ must be provided: | ||
<h3>grant_type=password</h3> | ||
This currently is the only grant type supported. | ||
* username __REQUIRED__. The resource owner username. Aka username for business customer portal | ||
* password __REQUIRED__. The resource owner password. Aka password for business customer portal | ||
* | ||
* @param \Mediaopt\DHL\Api\Authentication\Model\TokenPostBody $requestBody | ||
*/ | ||
public function __construct(\Mediaopt\DHL\Api\Authentication\Model\TokenPostBody $requestBody) | ||
{ | ||
$this->body = $requestBody; | ||
} | ||
use \Mediaopt\DHL\Api\Authentication\Runtime\Client\EndpointTrait; | ||
public function getMethod() : string | ||
{ | ||
return 'POST'; | ||
} | ||
public function getUri() : string | ||
{ | ||
return '/token'; | ||
} | ||
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null) : array | ||
{ | ||
if ($this->body instanceof \Mediaopt\DHL\Api\Authentication\Model\TokenPostBody) { | ||
return array(array('Content-Type' => array('application/x-www-form-urlencoded')), http_build_query($serializer->normalize($this->body, 'json'))); | ||
} | ||
return array(array(), null); | ||
} | ||
public function getExtraHeaders() : array | ||
{ | ||
return array('Accept' => array('application/json')); | ||
} | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenBadRequestException | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenUnauthorizedException | ||
* @throws \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenForbiddenException | ||
* | ||
* @return null|\Mediaopt\DHL\Api\Authentication\Model\TokenResponse | ||
*/ | ||
protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null) | ||
{ | ||
$status = $response->getStatusCode(); | ||
$body = (string) $response->getBody(); | ||
if (is_null($contentType) === false && (200 === $status && mb_strpos($contentType, 'application/json') !== false)) { | ||
return $serializer->deserialize($body, 'Mediaopt\\DHL\\Api\\Authentication\\Model\\TokenResponse', 'json'); | ||
} | ||
if (400 === $status) { | ||
throw new \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenBadRequestException($response); | ||
} | ||
if (401 === $status) { | ||
throw new \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenUnauthorizedException($response); | ||
} | ||
if (403 === $status) { | ||
throw new \Mediaopt\DHL\Api\Authentication\Exception\DispenseTokenForbiddenException($response); | ||
} | ||
} | ||
public function getAuthenticationScopes() : array | ||
{ | ||
return array('bearerAuth', 'basicAuth', 'apiKey'); | ||
} | ||
} |
Oops, something went wrong.