Abstract Class Yiisoft\Yii\AuthClient\AuthClient
AuthClient is a base Auth Client class.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $httpClient | \Psr\Http\Client\ClientInterface | Yiisoft\Yii\AuthClient\AuthClient | |
| $normalizeUserAttributeMap | array | Map used to normalize user attributes fetched from external auth service in format: normalizedAttributeName => sourceSpecification 'sourceSpecification' can be: - string, raw attribute name - array, pass to raw attribute value - callable, PHP callback, which should accept array of raw attributes and return normalized value. | Yiisoft\Yii\AuthClient\AuthClient |
| $requestFactory | \Psr\Http\Message\RequestFactoryInterface | Yiisoft\Yii\AuthClient\AuthClient | |
| $viewOptions | array | View options in format: optionName => optionValue | Yiisoft\Yii\AuthClient\AuthClient |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\AuthClient\AuthClient | |
| buildAuthUrl() | Yiisoft\Yii\AuthClient\AuthClient | |
| createRequest() | Yiisoft\Yii\AuthClient\AuthClient | |
| getButtonClass() | Yiisoft\Yii\AuthClient\AuthClientInterface | |
| getClientId() | The Client id is publically visible in button urls The Client secret must not be made available publically => exclude from interface | Yiisoft\Yii\AuthClient\AuthClientInterface |
| getName() | Yiisoft\Yii\AuthClient\AuthClientInterface | |
| getNormalizeUserAttributeMap() | Yiisoft\Yii\AuthClient\AuthClient | |
| getRequestFactory() | Yiisoft\Yii\AuthClient\AuthClient | |
| getTitle() | Yiisoft\Yii\AuthClient\AuthClientInterface | |
| getViewOptions() | Yiisoft\Yii\AuthClient\AuthClient | |
| setRequestFactory() | Yiisoft\Yii\AuthClient\AuthClient |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| defaultNormalizeUserAttributeMap() | Returns the default {@see normalizeUserAttributeMap} value. | Yiisoft\Yii\AuthClient\AuthClient |
| defaultViewOptions() | Returns the default {@see viewOptions} value. | Yiisoft\Yii\AuthClient\AuthClient |
| getState() | Returns persistent state value. | Yiisoft\Yii\AuthClient\AuthClient |
| getStateKeyPrefix() | Returns session key prefix, which is used to store internal states. | Yiisoft\Yii\AuthClient\AuthClient |
| removeState() | Removes persistent state value. | Yiisoft\Yii\AuthClient\AuthClient |
| sendRequest() | Yiisoft\Yii\AuthClient\AuthClient | |
| setState() | Sets persistent state. | Yiisoft\Yii\AuthClient\AuthClient |
Property Details
Map used to normalize user attributes fetched from external auth service in format: normalizedAttributeName => sourceSpecification 'sourceSpecification' can be:
- string, raw attribute name
- array, pass to raw attribute value
- callable, PHP callback, which should accept array of raw attributes and return normalized value.
For example:
'normalizeUserAttributeMap' => [
'about' => 'bio',
'language' => ['languages', 0, 'name'],
'fullName' => function ($attributes) {
return $attributes['firstName'] . ' ' . $attributes['lastName'];
},
],
View options in format: optionName => optionValue
Method Details
| public mixed __construct ( \Psr\Http\Client\ClientInterface $httpClient, \Psr\Http\Message\RequestFactoryInterface $requestFactory, Yiisoft\Yii\AuthClient\StateStorage\StateStorageInterface $stateStorage ) | ||
| $httpClient | \Psr\Http\Client\ClientInterface | |
| $requestFactory | \Psr\Http\Message\RequestFactoryInterface | |
| $stateStorage | Yiisoft\Yii\AuthClient\StateStorage\StateStorageInterface | |
public function __construct(
protected PsrClientInterface $httpClient,
protected RequestFactoryInterface $requestFactory,
/**
* @var StateStorageInterface state storage to be used.
*/
private readonly StateStorageInterface $stateStorage
) {
}
| public abstract string buildAuthUrl ( \Psr\Http\Message\ServerRequestInterface $incomingRequest, array $params ) | ||
| $incomingRequest | \Psr\Http\Message\ServerRequestInterface | |
| $params | array | |
#[\Override]
abstract public function buildAuthUrl(ServerRequestInterface $incomingRequest, array $params): string;
| public \Psr\Http\Message\RequestInterface createRequest ( string $method, string $uri ) | ||
| $method | string | |
| $uri | string | |
public function createRequest(string $method, string $uri): RequestInterface
{
return $this->requestFactory->createRequest($method, $uri);
}
Returns the default {@see normalizeUserAttributeMap} value.
Particular client may override this method in order to provide specific default map.
| protected array defaultNormalizeUserAttributeMap ( ) | ||
| return | array |
Normalize attribute map. |
|---|---|---|
protected function defaultNormalizeUserAttributeMap(): array
{
return [];
}
Returns the default {@see viewOptions} value.
Particular client may override this method in order to provide specific default view options.
| protected array defaultViewOptions ( ) | ||
| return | array |
List of default {@see \Yiisoft\Yii\AuthClient\viewOptions} |
|---|---|---|
protected function defaultViewOptions(): array
{
return [
'popupWidth' => 860,
'popupHeight' => 480,
];
}
| public abstract string getButtonClass ( ) |
public function getButtonClass(): string;
Defined in: Yiisoft\Yii\AuthClient\AuthClientInterface::getClientId()
The Client id is publically visible in button urls The Client secret must not be made available publically => exclude from interface
| public abstract string getClientId ( ) |
public function getClientId(): string;
| public array getNormalizeUserAttributeMap ( ) | ||
| return | array |
Normalize user attribute map. |
|---|---|---|
public function getNormalizeUserAttributeMap(): array
{
if (empty($this->normalizeUserAttributeMap)) {
$this->normalizeUserAttributeMap = $this->defaultNormalizeUserAttributeMap();
}
return $this->normalizeUserAttributeMap;
}
| public \Psr\Http\Message\RequestFactoryInterface getRequestFactory ( ) |
public function getRequestFactory(): RequestFactoryInterface
{
return $this->requestFactory;
}
Returns persistent state value.
| protected mixed getState ( string $key ) | ||
| $key | string |
State key. |
| return | mixed |
State value. |
|---|---|---|
protected function getState(string $key): mixed
{
return $this->stateStorage->get($this->getStateKeyPrefix() . $key);
}
Returns session key prefix, which is used to store internal states.
| protected string getStateKeyPrefix ( ) | ||
| return | string |
Session key prefix. |
|---|---|---|
protected function getStateKeyPrefix(): string
{
return static::class . '_' . $this->getName() . '_';
}
| public abstract string getTitle ( ) | ||
| return | string |
Service title. |
|---|---|---|
public function getTitle(): string;
| public array getViewOptions ( ) | ||
| return | array |
View options in format: optionName => optionValue |
|---|---|---|
#[\Override]
public function getViewOptions(): array
{
if (empty($this->viewOptions)) {
$this->viewOptions = $this->defaultViewOptions();
}
return $this->viewOptions;
}
Removes persistent state value.
| protected void removeState ( string $key ) | ||
| $key | string |
State key. |
protected function removeState(string $key): void
{
$this->stateStorage->remove($this->getStateKeyPrefix() . $key);
}
| protected \Psr\Http\Message\ResponseInterface sendRequest ( \Psr\Http\Message\RequestInterface $request ) | ||
| $request | \Psr\Http\Message\RequestInterface | |
protected function sendRequest(RequestInterface $request): ResponseInterface
{
return $this->httpClient->sendRequest($request);
}
| public void setRequestFactory ( \Psr\Http\Message\RequestFactoryInterface $requestFactory ) | ||
| $requestFactory | \Psr\Http\Message\RequestFactoryInterface | |
public function setRequestFactory(RequestFactoryInterface $requestFactory): void
{
$this->requestFactory = $requestFactory;
}
Signup or Login in order to comment.