From 8ff216d39ac1448a35c2d0a977b1be9d3913d7b3 Mon Sep 17 00:00:00 2001 From: Melvin Date: Tue, 24 Oct 2023 17:17:43 +0200 Subject: [PATCH] Updating Bearer class wrapper to instantiate it through object manager to have DI power and more custom classes --- Exceptions/InvalidBearerTokenException.php | 16 ------------ Http/Plugins/Auth/BearerPluginWrapper.php | 30 +++++++++++++--------- README.md | 7 +++-- 3 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 Exceptions/InvalidBearerTokenException.php diff --git a/Exceptions/InvalidBearerTokenException.php b/Exceptions/InvalidBearerTokenException.php deleted file mode 100644 index 3718bb7..0000000 --- a/Exceptions/InvalidBearerTokenException.php +++ /dev/null @@ -1,16 +0,0 @@ -objectManager = $objectManager; $this->bearerPluginClass = $bearerPluginClass; } - /** - * @throws InvalidBearerTokenException - */ public function create(array $options = []): AuthenticationPlugin { - if (!isset($options['Bearer'])) { - throw new InvalidBearerTokenException(); + $object = $this->objectManager->create($this->bearerPluginClass, $options); + + if (!$object instanceof AuthenticationPlugin) { + throw new RuntimeException( + sprintf( + '%s must implements %s', + get_class($object), + AuthenticationPlugin::class + ) + ); } - return new $this->bearerPluginClass($options['Bearer']); + return $object; } } diff --git a/README.md b/README.md index 2c06906..861e942 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # How to install -You can install it by typing : `composer require adexos/m2-jane-sdk-bridge:^1.0` +You can install it by typing : `composer require adexos/m2-jane-sdk-bridge` # How to use @@ -71,9 +71,8 @@ class MyClient { //This class allows you to have an attachment point to the HTTP client //and to have hint types because of the generic SDKs - //you can do whatever you want here such as doe somes checks or passing Bearer token : - // $this->tokenStrategy->getToken(); - // return $this->client->getClient(['Bearer' => $token]); + //you can do whatever you want here such as do some checks or passing scope for the bearer token : + // return $this->client->getClient(['scope' => 'my_custom_scope'']); return $this->client->getClient(); }