Resolves #2. Implemented authlib-injector support

This commit is contained in:
ErickSkrauch
2021-03-03 15:04:42 +01:00
parent 10ab237d1d
commit 4856695940
17 changed files with 505 additions and 87 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace common\components;
use GuzzleHttp\ClientInterface;
use Webmozart\Assert\Assert;
use Yii;
// TODO: convert to complete Chrly client library
@@ -11,8 +12,7 @@ class SkinsSystemApi {
private const BASE_DOMAIN = 'http://skinsystem.ely.by';
/** @var ClientInterface */
private $client;
private ?ClientInterface $client = null;
/**
* @param string $username
@@ -29,12 +29,47 @@ class SkinsSystemApi {
return json_decode($response->getBody()->getContents(), true);
}
/**
* @param string $username
*
* @return array|null
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function profile(string $username, bool $signed = false): ?array {
$url = "/profile/{$username}";
if ($signed) {
$url .= '?unsigned=false';
}
$response = $this->getClient()->request('GET', $this->buildUrl($url));
if ($response->getStatusCode() !== 200) {
return null;
}
return json_decode($response->getBody()->getContents(), true);
}
/**
* @param 'pem'|'der' $format
*
* @return string
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getSignatureVerificationKey(string $format = 'pem'): string {
Assert::inArray($format, ['pem', 'der']);
return $this->getClient()
->request('GET', $this->buildUrl("/signature-verification-key.{$format}"))
->getBody()
->getContents();
}
public function setClient(ClientInterface $client): void {
$this->client = $client;
}
private function buildUrl(string $url): string {
return self::BASE_DOMAIN . $url;
return static::BASE_DOMAIN . $url;
}
private function getClient(): ClientInterface {