0 follower

Abstract Class Yiisoft\Yii\AuthClient\AuthClient

InheritanceYiisoft\Yii\AuthClient\AuthClient
ImplementsYiisoft\Yii\AuthClient\AuthClientInterface
SubclassesYiisoft\Yii\AuthClient\Client\Facebook, Yiisoft\Yii\AuthClient\Client\GitHub, Yiisoft\Yii\AuthClient\Client\Google, Yiisoft\Yii\AuthClient\Client\LinkedIn, Yiisoft\Yii\AuthClient\Client\MicrosoftOnline, Yiisoft\Yii\AuthClient\Client\OpenIdConnect, Yiisoft\Yii\AuthClient\Client\TikTok, Yiisoft\Yii\AuthClient\Client\VKontakte, Yiisoft\Yii\AuthClient\Client\X, Yiisoft\Yii\AuthClient\Client\Yandex, Yiisoft\Yii\AuthClient\OAuth, Yiisoft\Yii\AuthClient\OAuth2

AuthClient is a base Auth Client class.

See also Yiisoft\Yii\AuthClient\AuthClientInterface.

Protected Properties

Hide inherited 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

Protected Methods

Hide inherited 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

Hide inherited properties

$httpClient protected property
protected \Psr\Http\Client\ClientInterface $httpClient null
$normalizeUserAttributeMap protected property

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'];
     },
 ],
$requestFactory protected property
protected \Psr\Http\Message\RequestFactoryInterface $requestFactory null
$viewOptions protected property

View options in format: optionName => optionValue

protected array $viewOptions null

Method Details

Hide inherited methods

__construct() public method

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
) {
}

            
buildAuthUrl() public abstract method

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;

            
createRequest() public method

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);
}

            
defaultNormalizeUserAttributeMap() protected method

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 [];
}

            
defaultViewOptions() protected method

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,
    ];
}

            
getButtonClass() public abstract method
public abstract string getButtonClass ( )

                public function getButtonClass(): string;

            
getClientId() public abstract method

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;

            
getName() public abstract method
public abstract string getName ( )
return string

Service name.

                public function getName(): string;

            
getNormalizeUserAttributeMap() public method

public array getNormalizeUserAttributeMap ( )
return array

Normalize user attribute map.

                public function getNormalizeUserAttributeMap(): array
{
    if (empty($this->normalizeUserAttributeMap)) {
        $this->normalizeUserAttributeMap = $this->defaultNormalizeUserAttributeMap();
    }
    return $this->normalizeUserAttributeMap;
}

            
getRequestFactory() public method

public \Psr\Http\Message\RequestFactoryInterface getRequestFactory ( )

                public function getRequestFactory(): RequestFactoryInterface
{
    return $this->requestFactory;
}

            
getState() protected method

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);
}

            
getStateKeyPrefix() protected method

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() . '_';
}

            
getTitle() public abstract method
public abstract string getTitle ( )
return string

Service title.

                public function getTitle(): string;

            
getViewOptions() public method

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;
}

            
removeState() protected method

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);
}

            
sendRequest() protected method

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);
}

            
setRequestFactory() public method

public void setRequestFactory ( \Psr\Http\Message\RequestFactoryInterface $requestFactory )
$requestFactory \Psr\Http\Message\RequestFactoryInterface

                public function setRequestFactory(RequestFactoryInterface $requestFactory): void
{
    $this->requestFactory = $requestFactory;
}

            
setState() protected method

Sets persistent state.

protected $this setState ( string $key, mixed $value )
$key string

State key.

$value mixed

State value

return $this

The object itself

                protected function setState(string $key, $value): self
{
    $this->stateStorage->set($this->getStateKeyPrefix() . $key, $value);
    return $this;
}