-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor sso driver with separate class
- Loading branch information
Showing
12 changed files
with
459 additions
and
253 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Classid\SsoDriver; | ||
|
||
|
||
class HttpClientService implements \Classid\SsoDriver\Interfaces\HttpClient | ||
{ | ||
public array $httpRequestHeaders; | ||
public string $baseUrl; | ||
|
||
public function __construct() | ||
{ | ||
$this->setDefaultHttpRequestHeader() | ||
->setBaseUrl(); | ||
} | ||
|
||
/** | ||
* @return HttpClientService | ||
*/ | ||
public function setBaseUrl(): HttpClientService | ||
{ | ||
$this->baseUrl = rtrim(config("mumtaz_sso_driver.host"), "/"); | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBaseUrl(): string | ||
{ | ||
return $this->baseUrl; | ||
} | ||
|
||
|
||
/** | ||
* @return HttpClientService | ||
*/ | ||
public function setDefaultHttpRequestHeader(): HttpClientService | ||
{ | ||
$this->httpRequestHeaders = [ | ||
"Accept" => "application/json" | ||
]; | ||
|
||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param array $httpRequestHeaders | ||
* @return HttpClientService | ||
*/ | ||
public function setHttpRequestHeaders(array $httpRequestHeaders): HttpClientService | ||
{ | ||
$this->httpRequestHeaders = $httpRequestHeaders; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param string $key | ||
* @param string|array $value | ||
* @return HttpClientService | ||
*/ | ||
public function addHttpRequestHeader(string $key, string|array $value): HttpClientService | ||
{ | ||
$this->httpRequestHeaders[$key] = $value; | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @param array $httpRequestHeaders | ||
* @return HttpClientService | ||
*/ | ||
public function addHttpRequestHeaders(array $httpRequestHeaders): HttpClientService | ||
{ | ||
$this->httpRequestHeaders = array_merge($this->httpRequestHeaders, $httpRequestHeaders); | ||
return $this; | ||
} | ||
|
||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHttpRequestHeaders(): array | ||
{ | ||
return $this->httpRequestHeaders; | ||
} | ||
|
||
|
||
/** | ||
* @param string $key | ||
* @return array | ||
*/ | ||
public function getHttpRequestHeader(string $key): array | ||
{ | ||
return $this->httpRequestHeaders[$key]; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace Classid\SsoDriver\Interfaces; | ||
|
||
|
||
|
||
interface HttpClient | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getBaseUrl():string; | ||
|
||
/** | ||
* @return HttpClient | ||
*/ | ||
public function setBaseUrl():HttpClient; | ||
|
||
/** | ||
* @return HttpClient | ||
*/ | ||
public function setDefaultHttpRequestHeader(): HttpClient; | ||
|
||
/** | ||
* @param array $httpRequestHeaders | ||
* @return HttpClient | ||
*/ | ||
public function setHttpRequestHeaders(array $httpRequestHeaders): HttpClient; | ||
|
||
/** | ||
* @param string $key | ||
* @param string|array $value | ||
* @return $this | ||
*/ | ||
public function addHttpRequestHeader(string $key, string|array $value): HttpClient; | ||
|
||
/** | ||
* @param array $httpRequestHeaders | ||
* @return HttpClient | ||
*/ | ||
public function addHttpRequestHeaders(array $httpRequestHeaders): HttpClient; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHttpRequestHeaders(): array; | ||
|
||
/** | ||
* @param string $key | ||
* @return array | ||
*/ | ||
public function getHttpRequestHeader(string $key):array; | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Classid\SsoDriver\Interfaces; | ||
|
||
|
||
use Classid\SsoDriver\Exceptions\InvalidClientCredentials; | ||
use Classid\SsoDriver\Exceptions\InvalidRetryGenerateException; | ||
use Classid\SsoDriver\Exceptions\SSODriverException; | ||
use Classid\SsoDriver\Exceptions\UnknownErrorHandlerException; | ||
|
||
interface OauthToken | ||
{ | ||
/** | ||
* @param array|null $errorResponse | ||
* @return bool | ||
* @throws InvalidClientCredentials | ||
* @throws SSODriverException | ||
* @throws UnknownErrorHandlerException|InvalidRetryGenerateException | ||
*/ | ||
public function isRetryOnInvalidAccessToken(?array $errorResponse): bool; | ||
|
||
|
||
/** | ||
* @param bool $isRegenerate | ||
* @return string | ||
* @throws InvalidClientCredentials | ||
* @throws SSODriverException | ||
* @throws UnknownErrorHandlerException | ||
*/ | ||
public function getClientAccessToken(bool $isRegenerate = false): string; | ||
} |
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 Classid\SsoDriver\Interfaces; | ||
|
||
|
||
use Classid\SsoDriver\Exceptions\InvalidClientCredentials; | ||
use Classid\SsoDriver\Exceptions\InvalidRetryGenerateException; | ||
use Classid\SsoDriver\Exceptions\SSODriverException; | ||
use Classid\SsoDriver\Exceptions\UnknownErrorHandlerException; | ||
|
||
interface SSO | ||
{ | ||
/** | ||
* @return $this | ||
* @throws InvalidClientCredentials | ||
* @throws SSODriverException | ||
* @throws UnknownErrorHandlerException | ||
*/ | ||
public function setAuthorizationToken(): self; | ||
|
||
|
||
/** | ||
* @param callable $request | ||
* @param callable|null $customErrorHandler | ||
* @return object|null | ||
* @throws InvalidRetryGenerateException|UnknownErrorHandlerException|InvalidClientCredentials|SSODriverException | ||
*/ | ||
public function getResponse(callable $request, callable $customErrorHandler = null): ?object; | ||
} |
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
Oops, something went wrong.