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 $normalizeUserAttributeMap value. Yiisoft\Yii\AuthClient\AuthClient
defaultViewOptions() Returns the default $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 __construct( \Psr\Http\Client\ClientInterface $httpClient, \Psr\Http\Message\RequestFactoryInterface $requestFactory, Yiisoft\Yii\AuthClient\StateStorage\StateStorageInterface $stateStorage ): mixed
$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 buildAuthUrl( \Psr\Http\Message\ServerRequestInterface $incomingRequest, array $params ): string
$incomingRequest \Psr\Http\Message\ServerRequestInterface
$params array

                #[\Override]
abstract public function buildAuthUrl(ServerRequestInterface $incomingRequest, array $params): string;

            
createRequest() public method

public createRequest( string $method, string $uri ): \Psr\Http\Message\RequestInterface
$method string
$uri string

                public function createRequest(string $method, string $uri): RequestInterface
{
    return $this->requestFactory->createRequest($method, $uri);
}

            
defaultNormalizeUserAttributeMap() protected method

Returns the default $normalizeUserAttributeMap value.

Particular client may override this method in order to provide specific default map.

protected defaultNormalizeUserAttributeMap( ): array
return array

Normalize attribute map.

                protected function defaultNormalizeUserAttributeMap(): array
{
    return [];
}

            
defaultViewOptions() protected method

Returns the default $viewOptions value.

Particular client may override this method in order to provide specific default view options.

protected defaultViewOptions( ): array
return array

List of default $viewOptions

                protected function defaultViewOptions(): array
{
    return [
        'popupWidth' => 860,
        'popupHeight' => 480,
    ];
}

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

                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 getClientId( ): string

                public function getClientId(): string;

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

Service name.

                public function getName(): string;

            
getNormalizeUserAttributeMap() public method

public getNormalizeUserAttributeMap( ): array
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 getRequestFactory( ): \Psr\Http\Message\RequestFactoryInterface

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

            
getState() protected method

Returns persistent state value.

protected getState( string $key ): mixed
$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 getStateKeyPrefix( ): string
return string

Session key prefix.

                protected function getStateKeyPrefix(): string
{
    return static::class . '_' . $this->getName() . '_';
}

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

Service title.

                public function getTitle(): string;

            
getViewOptions() public method

public getViewOptions( ): array
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 removeState( string $key ): void
$key string

State key.

                protected function removeState(string $key): void
{
    $this->stateStorage->remove($this->getStateKeyPrefix() . $key);
}

            
sendRequest() protected method

protected sendRequest( \Psr\Http\Message\RequestInterface $request ): \Psr\Http\Message\ResponseInterface
$request \Psr\Http\Message\RequestInterface

                protected function sendRequest(RequestInterface $request): ResponseInterface
{
    return $this->httpClient->sendRequest($request);
}

            
setRequestFactory() public method

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

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

            
setState() protected method

Sets persistent state.

protected setState( string $key, mixed $value ): $this
$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;
}