Final Class Yiisoft\Yii\AuthClient\Client\Facebook
Facebook allows authentication via Facebook OAuth.
In order to use Facebook OAuth you must register your application at https://developers.facebook.com/apps
Example application configuration:
config/common/params.php
'yiisoft/yii-auth-client' => [
'enabled' => true,
'clients' => [
'facebook' => [
'class' => 'Yiisoft\Yii\AuthClient\Client\Facebook::class',
'clientId' => $_ENV['FACEBOOK_API_CLIENT_ID'] ?? '',
'clientSecret' => $_ENV['FACEBOOK_API_CLIENT_SECRET'] ?? '',
'returnUrl' => $_ENV['FACEBOOK_API_CLIENT_RETURN_URL'] ?? '',
],
],
],
Protected Properties
Public Methods
Protected Methods
Property Details
Method Details
Defined in: Yiisoft\Yii\AuthClient\OAuth2::__construct()
BaseOAuth constructor.
| public __construct( \Psr\Http\Client\ClientInterface $httpClient, \Psr\Http\Message\RequestFactoryInterface $requestFactory, Yiisoft\Yii\AuthClient\StateStorage\StateStorageInterface $stateStorage, \Yiisoft\Factory\Factory $factory, \Yiisoft\Session\SessionInterface $session ): mixed | ||
| $httpClient | \Psr\Http\Client\ClientInterface | |
| $requestFactory | \Psr\Http\Message\RequestFactoryInterface | |
| $stateStorage | Yiisoft\Yii\AuthClient\StateStorage\StateStorageInterface | |
| $factory | \Yiisoft\Factory\Factory | |
| $session | \Yiisoft\Session\SessionInterface | |
public function __construct(
ClientInterface $httpClient,
RequestFactoryInterface $requestFactory,
StateStorageInterface $stateStorage,
protected YiisoftFactory $factory,
protected SessionInterface $session,
) {
parent::__construct($httpClient, $requestFactory, $stateStorage, $this->factory);
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::api()
Performs request to the OAuth API returning response data.
You may use createApiRequest() method instead, gaining more control over request execution.
See also createApiRequest().
| public api( string $apiSubUrl, string $method = 'GET', array|string $data = [], array $headers = [] ): array | ||
| $apiSubUrl | string |
API sub URL, which will be append to \Yiisoft\Yii\AuthClient\apiBaseUrl, or absolute API URL. |
| $method | string |
Request method. |
| $data | array|string |
Request data or content. |
| $headers | array |
Additional request headers. |
| return | array |
API response data. |
|---|---|---|
| throws | Exception | |
public function api($apiSubUrl, $method = 'GET', $data = [], $headers = []): array
{
$request = $this->createApiRequest($method, $apiSubUrl);
$request = RequestUtil::addHeaders($request, $headers);
if (!empty($data)) {
if (is_array($data)) {
$request = RequestUtil::addParams($request, $data);
} else {
$request->getBody()->write($data);
}
}
$request = $this->beforeApiRequestSend($request);
$response = $this->sendRequest($request);
if ($response->getStatusCode() !== 200) {
throw new InvalidResponseException(
$response,
'Request failed with code: ' . $response->getStatusCode() . ', message: ' . (string)$response->getBody()
);
}
return (array)Json::decode($response->getBody()->getContents());
}
| public applyAccessTokenToRequest( \Psr\Http\Message\RequestInterface $request, Yiisoft\Yii\AuthClient\OAuthToken $accessToken ): \Psr\Http\Message\RequestInterface | ||
| $request | \Psr\Http\Message\RequestInterface | |
| $accessToken | Yiisoft\Yii\AuthClient\OAuthToken | |
#[\Override]
public function applyAccessTokenToRequest(RequestInterface $request, OAuthToken $accessToken): RequestInterface
{
$request = parent::applyAccessTokenToRequest($request, $accessToken);
$params = [];
if (!empty($machineId = (string)$accessToken->getParam('machine_id'))) {
$params['machine_id'] = $machineId;
}
$token = $accessToken->getToken();
if (null !== $token) {
$params['appsecret_proof'] = hash_hmac('sha256', $token, $this->clientSecret);
}
return RequestUtil::addParams($request, $params);
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::applyClientCredentialsToRequest()
Applies client credentials (e.g. $clientId and $clientSecret) to the HTTP request instance.
This method should be invoked before sending any HTTP request, which requires client credentials.
| protected applyClientCredentialsToRequest( \Psr\Http\Message\RequestInterface $request ): \Psr\Http\Message\RequestInterface | ||
| $request | \Psr\Http\Message\RequestInterface |
HTTP request instance. |
protected function applyClientCredentialsToRequest(RequestInterface $request): RequestInterface
{
return RequestUtil::addParams(
$request,
[
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
]
);
}
| public beforeApiRequestSend( \Psr\Http\Message\RequestInterface $request ): \Psr\Http\Message\RequestInterface | ||
| $request | \Psr\Http\Message\RequestInterface | |
public function beforeApiRequestSend(RequestInterface $request): RequestInterface
{
$accessToken = $this->getAccessToken();
if (!is_object($accessToken) || !$accessToken->getIsValid()) {
throw new Exception('Invalid access token.');
}
return $this->applyAccessTokenToRequest($request, $accessToken);
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::buildAuthUrl()
Composes user authorization URL.
| public buildAuthUrl( \Psr\Http\Message\ServerRequestInterface $incomingRequest, array $params = [] ): string | ||
| $incomingRequest | \Psr\Http\Message\ServerRequestInterface | |
| $params | array |
Additional auth GET params. |
| return | string |
Authorization URL. |
|---|---|---|
#[\Override]
public function buildAuthUrl(
ServerRequestInterface $incomingRequest,
array $params = []
): string {
$defaultParams = [
'client_id' => $this->clientId,
'response_type' => 'code',
'redirect_uri' => $this->getOauth2ReturnUrl(),
'xoauth_displayname' => $incomingRequest->getAttribute(AuthAction::AUTH_NAME),
];
if (!empty($this->getScope())) {
$defaultParams['scope'] = $this->getScope();
}
if ($this->validateAuthState) {
$authState = $this->generateAuthState();
$this->setState('authState', $authState);
$defaultParams['state'] = $authState;
}
return RequestUtil::composeUrl($this->authUrl, array_merge($defaultParams, $params));
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::createApiRequest()
Creates an HTTP request for the API call.
The created request will be automatically processed adding access token parameters and signature before sending. You may use createRequest() to gain full control over request composition and execution.
See also createRequest().
| public createApiRequest( string $method, string $uri ): \Psr\Http\Message\RequestInterface | ||
| $method | string | |
| $uri | string | |
| return | \Psr\Http\Message\RequestInterface |
HTTP request instance. |
|---|---|---|
public function createApiRequest(string $method, string $uri): RequestInterface
{
return $this->createRequest($method, $this->endpoint . $uri);
}
| 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);
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::createToken()
Creates token from its configuration.
| protected createToken( array $tokenConfig = [] ): Yiisoft\Yii\AuthClient\OAuthToken | ||
| $tokenConfig | array |
Token configuration. |
| return | Yiisoft\Yii\AuthClient\OAuthToken |
Token instance. |
|---|---|---|
#[\Override]
protected function createToken(array $tokenConfig = []): OAuthToken
{
$tokenConfig['tokenParamKey'] = 'access_token';
return parent::createToken($tokenConfig);
}
Defined in: Yiisoft\Yii\AuthClient\AuthClient::defaultNormalizeUserAttributeMap()
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 [];
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::defaultReturnUrl()
Composes default $returnUrl value.
| protected defaultReturnUrl( \Psr\Http\Message\ServerRequestInterface $request ): string | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
| return | string |
Return URL. |
|---|---|---|
#[\Override]
protected function defaultReturnUrl(ServerRequestInterface $request): string
{
$params = $request->getQueryParams();
unset($params['code'], $params['state']);
return (string)$request->getUri()->withQuery(http_build_query($params, '', '&', PHP_QUERY_RFC3986));
}
| protected defaultViewOptions( ): integer[] |
#[\Override]
protected function defaultViewOptions(): array
{
return [
'popupWidth' => 860,
'popupHeight' => 480,
];
}
Exchanges short-live (2 hours) access token to long-live (60 days) one.
Note that this method will success for already long-live token, but will not actually prolong it any further. Pay attention, that this method will fail on already expired access token.
| public exchangeAccessToken( Yiisoft\Yii\AuthClient\OAuthToken $token ): Yiisoft\Yii\AuthClient\OAuthToken | ||
| $token | Yiisoft\Yii\AuthClient\OAuthToken |
Short-live access token. |
| return | Yiisoft\Yii\AuthClient\OAuthToken |
Long-live access token. |
|---|---|---|
public function exchangeAccessToken(OAuthToken $token): OAuthToken
{
[
'grant_type' => 'fb_exchange_token',
'fb_exchange_token' => $token->getToken(),
];
$request = $this->createRequest('POST', $this->getTokenUrl());
//->setParams($params);
$this->applyClientCredentialsToRequest($request);
$response = $this->sendRequest($request);
$token = $this->createToken(['params' => $response]);
$this->setAccessToken($token);
return $token;
}
| public fetchAccessToken( \Psr\Http\Message\ServerRequestInterface $incomingRequest, string $authCode, array $params = [] ): Yiisoft\Yii\AuthClient\OAuthToken | ||
| $incomingRequest | \Psr\Http\Message\ServerRequestInterface | |
| $authCode | string | |
| $params | array | |
#[\Override]
public function fetchAccessToken(ServerRequestInterface $incomingRequest, string $authCode, array $params = []): OAuthToken
{
$token = parent::fetchAccessToken($incomingRequest, $authCode, $params);
if ($this->autoExchangeAccessToken) {
$token = $this->exchangeAccessToken($token);
}
return $token;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::fetchAccessTokenWithCodeVerifier()
Note: This function will be adapted later to accomodate the 'confidential client'.
See also https://docs.x.com/resources/fundamentals/authentication/oauth-2-0/authorization-code Used specifically for the X i.e. Twitter OAuth2.0 Authorization code with PKCE and public client i.e. client id included in request body; and NOT Confidential Client i.e. Client id not included in the request body.
| public fetchAccessTokenWithCodeVerifier( \Psr\Http\Message\ServerRequestInterface $incomingRequest, string $authCode, array $params = [] ): Yiisoft\Yii\AuthClient\OAuthToken | ||
| $incomingRequest | \Psr\Http\Message\ServerRequestInterface | |
| $authCode | string | |
| $params | array | |
| throws | InvalidArgumentException | |
|---|---|---|
public function fetchAccessTokenWithCodeVerifier(
ServerRequestInterface $incomingRequest,
string $authCode,
array $params = [],
): OAuthToken {
if ($this->validateAuthState) {
/**
* @psalm-suppress MixedAssignment
*/
$authState = $this->getState('authState');
$queryParams = $incomingRequest->getQueryParams();
$bodyParams = $incomingRequest->getParsedBody();
/**
* @psalm-suppress MixedAssignment
*/
$incomingState = $queryParams['state'] ?? ($bodyParams['state'] ?? null);
if (is_string($incomingState)) {
if (strcmp($incomingState, (string)$authState) !== 0) {
throw new InvalidArgumentException('Invalid auth state parameter.');
}
}
if ($incomingState === null) {
throw new InvalidArgumentException('Invalid auth state parameter.');
}
if (empty($authState)) {
throw new InvalidArgumentException('Invalid auth state parameter.');
}
$this->removeState('authState');
}
$requestBody = [
'code' => $authCode,
'grant_type' => 'authorization_code',
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $params['redirect_uri'] ?? '',
'code_verifier' => $params['code_verifier'] ?? '',
];
$request = $this->requestFactory
->createRequest('POST', $this->tokenUrl)
->withHeader('Content-Type', 'application/x-www-form-urlencoded');
$request->getBody()->write(http_build_query($requestBody));
try {
$response = $this->httpClient->sendRequest($request);
$body = $response->getBody()->getContents();
if (strlen($body) > 0) {
$output = (array) json_decode($body, true);
} else {
$output = [];
}
} catch (\Throwable $e) {
$output = [];
}
$token = new OAuthToken();
/**
* @var string $key
* @var string $value
*/
foreach ($output as $key => $value) {
$token->setParam($key, $value);
}
return $token;
}
Fetches access token from client-specific authorization code.
This make sense for the distributed applications, which provides several Auth clients (web and mobile) to avoid triggering Facebook's automated spam systems.
See also fetchClientAuthCode().
| public fetchClientAccessToken( \Psr\Http\Message\ServerRequestInterface $incomingRequest, string $authCode, array $params = [] ): Yiisoft\Yii\AuthClient\OAuthToken | ||
| $incomingRequest | \Psr\Http\Message\ServerRequestInterface | |
| $authCode | string |
Client auth code. |
| $params | array | |
| return | Yiisoft\Yii\AuthClient\OAuthToken |
Long-live client-specific access token. |
|---|---|---|
public function fetchClientAccessToken(
ServerRequestInterface $incomingRequest,
string $authCode,
array $params = []
): OAuthToken {
$params = array_merge(
[
'code' => $authCode,
'redirect_uri' => $this->getReturnUrl($incomingRequest),
'client_id' => $this->clientId,
],
$params
);
$request = $this->createRequest('POST', $this->getTokenUrl());
$request = RequestUtil::addParams($request, $params);
$response = $this->sendRequest($request);
$token = $this->createToken(['params' => $response]);
$this->setAccessToken($token);
return $token;
}
Requests the authorization code for the client-specific access token.
This make sense for the distributed applications, which provides several Auth clients (web and mobile) to avoid triggering Facebook's automated spam systems.
See also fetchClientAccessToken().
| public fetchClientAuthCode( \Psr\Http\Message\ServerRequestInterface $incomingRequest, Yiisoft\Yii\AuthClient\OAuthToken|null $token = null, array $params = [] ): numeric-string | ||
| $incomingRequest | \Psr\Http\Message\ServerRequestInterface | |
| $token | Yiisoft\Yii\AuthClient\OAuthToken|null |
Access token, if not set $accessToken will be used. |
| $params | array |
Additional request params. |
| return | numeric-string |
Client auth code. |
|---|---|---|
public function fetchClientAuthCode(
ServerRequestInterface $incomingRequest,
OAuthToken $token = null,
array $params = []
): string {
if ($token === null) {
$token = $this->getAccessToken();
}
if (null !== $token) {
$params = array_merge(
[
'access_token' => $token->getToken(),
'redirect_uri' => $this->getReturnUrl($incomingRequest),
],
$params
);
}
$request = $this->createRequest('POST', $this->clientAuthCodeUrl);
$request = RequestUtil::addParams($request, $params);
$request = $this->applyClientCredentialsToRequest($request);
$response = $this->sendRequest($request);
return (string)$response->getStatusCode();
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::generateAuthState()
Generates the auth state value.
| protected generateAuthState( ): string | ||
| return | string |
Auth state value. |
|---|---|---|
protected function generateAuthState(): string
{
$baseString = static::class . '-' . time();
$sessionId = $this->session->getId();
if (null !== $sessionId) {
if ($this->session->isActive()) {
$baseString .= '-' . $sessionId;
}
}
return hash('sha256', uniqid($baseString, true));
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::getAccessToken()
| public getAccessToken( ): Yiisoft\Yii\AuthClient\OAuthToken|null | ||
| return | Yiisoft\Yii\AuthClient\OAuthToken|null |
Auth token instance. |
|---|---|---|
public function getAccessToken(): ?OAuthToken
{
if (!is_object($this->accessToken)) {
$this->accessToken = $this->restoreAccessToken();
}
return $this->accessToken;
}
| public getButtonClass( ): string |
#[\Override]
public function getButtonClass(): string
{
return 'btn btn-primary bi bi-facebook';
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::getClientId()
| public getClientId( ): string |
#[\Override]
public function getClientId(): string
{
return $this->clientId;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::getClientSecret()
| public getClientSecret( ): string |
public function getClientSecret(): string
{
return $this->clientSecret;
}
| public getCurrentUserJsonArray( Yiisoft\Yii\AuthClient\OAuthToken $token ): array | ||
| $token | Yiisoft\Yii\AuthClient\OAuthToken | |
public function getCurrentUserJsonArray(OAuthToken $token): array
{
$params = $token->getParams();
$finalValue = '';
$finalValue = array_key_last($params);
/**
* @var string $finalValue
* @var array $array
*/
$array = json_decode($finalValue, true);
$tokenString = (string)($array['access_token'] ?? '');
if ($tokenString !== '') {
$queryParams = [
'fields' => implode(',', $this->endpointFields),
];
$url = sprintf(
$this->endpoint . '/%s/me?%s',
urlencode($this->graphApiVersion),
http_build_query($queryParams)
);
$request = $this->createRequest('GET', $url);
$request = RequestUtil::addHeaders(
$request,
[
'Authorization' => 'Bearer ' . $tokenString,
]
);
$response = $this->sendRequest($request);
return (array) json_decode($response->getBody()->getContents(), true);
}
return [];
}
| protected getDefaultScope( ): string |
#[\Override]
protected function getDefaultScope(): string
{
return 'public_profile';
}
| public getNormalizeUserAttributeMap( ): array | ||
| return | array |
Normalize user attribute map. |
|---|---|---|
public function getNormalizeUserAttributeMap(): array
{
if (empty($this->normalizeUserAttributeMap)) {
$this->normalizeUserAttributeMap = $this->defaultNormalizeUserAttributeMap();
}
return $this->normalizeUserAttributeMap;
}
| public getOauth2ReturnUrl( ): string |
public function getOauth2ReturnUrl(): string
{
return $this->returnUrl;
}
| public getRequestFactory( ): \Psr\Http\Message\RequestFactoryInterface |
public function getRequestFactory(): RequestFactoryInterface
{
return $this->requestFactory;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::getReturnUrl()
| public getReturnUrl( \Psr\Http\Message\ServerRequestInterface $request ): string | ||
| $request | \Psr\Http\Message\ServerRequestInterface | |
| return | string |
Return URL. |
|---|---|---|
public function getReturnUrl(ServerRequestInterface $request): string
{
if ($this->returnUrl === '') {
$this->returnUrl = $this->defaultReturnUrl($request);
}
return $this->returnUrl;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::getScope()
| public getScope( ): string |
public function getScope(): string
{
if ($this->scope === null) {
return $this->getDefaultScope();
}
return $this->scope;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::getSessionAuthState()
Compare a callback query parameter 'state' with the saved Auth Client's 'authState' parameter in order to prevent CSRF attacks
Use: Typically used in a AuthController's callback function specifically for an Identity Provider e.g. Facebook
| public getSessionAuthState( ): mixed |
public function getSessionAuthState(): mixed
{
/**
* @see src\AuthClient protected function getState('authState')
*/
return $this->getState('authState');
}
Defined in: Yiisoft\Yii\AuthClient\AuthClient::getState()
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);
}
Defined in: Yiisoft\Yii\AuthClient\AuthClient::getStateKeyPrefix()
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() . '_';
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::getTokenUrl()
| public getTokenUrl( ): string |
public function getTokenUrl(): string
{
return $this->tokenUrl;
}
| 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;
}
| public getYiisoftFactory( ): \Yiisoft\Factory\Factory |
public function getYiisoftFactory(): YiisoftFactory
{
return $this->factory;
}
| protected initUserAttributes( ): array |
protected function initUserAttributes(): array
{
$token = $this->getAccessToken();
if ($token instanceof OAuthToken) {
return $this->getCurrentUserJsonArray($token);
}
return [];
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::refreshAccessToken()
Gets new auth token to replace expired one.
| public refreshAccessToken( Yiisoft\Yii\AuthClient\OAuthToken $token ): Yiisoft\Yii\AuthClient\OAuthToken | ||
| $token | Yiisoft\Yii\AuthClient\OAuthToken |
Expired auth token. |
| return | Yiisoft\Yii\AuthClient\OAuthToken |
New auth token. |
|---|---|---|
#[\Override]
public function refreshAccessToken(OAuthToken $token): OAuthToken
{
$params = [
'grant_type' => 'refresh_token',
];
$params = array_merge($token->getParams(), $params);
$request = $this->createRequest('POST', $this->tokenUrl);
$request = RequestUtil::addParams($request, $params);
$request = $this->applyClientCredentialsToRequest($request);
$response = $this->sendRequest($request);
$contents = $response->getBody()->getContents();
$output = $this->parse_str_clean($contents);
$token = new OAuthToken();
/**
* @var string $key
* @var string $value
*/
foreach ($output as $key => $value) {
$token->setParam($key, $value);
}
return $token;
}
Defined in: Yiisoft\Yii\AuthClient\AuthClient::removeState()
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);
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::restoreAccessToken()
Restores access token.
| protected restoreAccessToken( ): Yiisoft\Yii\AuthClient\OAuthToken|null |
protected function restoreAccessToken(): ?OAuthToken
{
/**
* @psalm-suppress MixedAssignment $token
*/
if (($token = $this->getState('token')) instanceof OAuthToken) {
if ($token->getIsExpired() && $this->autoRefreshAccessToken) {
return $this->refreshAccessToken($token);
}
return $token;
}
return null;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::saveAccessToken()
Saves token as persistent state.
| protected saveAccessToken( Yiisoft\Yii\AuthClient\OAuthToken|null $token = null ): $this | ||
| $token | Yiisoft\Yii\AuthClient\OAuthToken|null |
Auth token to be saved. |
| return | $this |
The object itself. |
|---|---|---|
protected function saveAccessToken(OAuthToken $token = null): self
{
return $this->setState('token', $token);
}
Defined in: Yiisoft\Yii\AuthClient\AuthClient::sendRequest()
| 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);
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::setAccessToken()
Sets access token to be used.
| public setAccessToken( array|Yiisoft\Yii\AuthClient\OAuthToken $token ): void | ||
| $token | array|Yiisoft\Yii\AuthClient\OAuthToken |
Access token or its configuration. |
public function setAccessToken(array|OAuthToken $token): void
{
if (is_array($token) && !empty($token)) {
/**
* @psalm-suppress MixedAssignment $newToken
*/
$newToken = $this->createToken($token);
/**
* @psalm-suppress MixedAssignment $this->accessToken
*/
$this->accessToken = $newToken;
/**
* @psalm-suppress MixedArgument $newToken
*/
$this->saveAccessToken($newToken);
}
if ($token instanceof OAuthToken) {
$this->accessToken = $token;
$this->saveAccessToken($token);
}
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::setAuthUrl()
| public setAuthUrl( string $authUrl ): void | ||
| $authUrl | string | |
public function setAuthUrl(string $authUrl): void
{
$this->authUrl = $authUrl;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::setClientId()
| public setClientId( string $clientId ): void | ||
| $clientId | string | |
public function setClientId(string $clientId): void
{
$this->clientId = $clientId;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::setClientSecret()
| public setClientSecret( string $clientSecret ): void | ||
| $clientSecret | string | |
public function setClientSecret(string $clientSecret): void
{
$this->clientSecret = $clientSecret;
}
| public setOauth2ReturnUrl( string $returnUrl ): void | ||
| $returnUrl | string | |
public function setOauth2ReturnUrl(string $returnUrl): void
{
$this->returnUrl = $returnUrl;
}
| public setRequestFactory( \Psr\Http\Message\RequestFactoryInterface $requestFactory ): void | ||
| $requestFactory | \Psr\Http\Message\RequestFactoryInterface | |
public function setRequestFactory(RequestFactoryInterface $requestFactory): void
{
$this->requestFactory = $requestFactory;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth::setReturnUrl()
| public setReturnUrl( string $returnUrl ): void | ||
| $returnUrl | string |
Return URL |
public function setReturnUrl(string $returnUrl): void
{
$this->returnUrl = $returnUrl;
}
Defined in: Yiisoft\Yii\AuthClient\AuthClient::setState()
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;
}
Defined in: Yiisoft\Yii\AuthClient\OAuth2::setTokenUrl()
| public setTokenUrl( string $tokenUrl ): void | ||
| $tokenUrl | string | |
public function setTokenUrl(string $tokenUrl): void
{
$this->tokenUrl = $tokenUrl;
}
| public setYiisoftFactory( \Yiisoft\Factory\Factory $factory ): void | ||
| $factory | \Yiisoft\Factory\Factory | |
public function setYiisoftFactory(YiisoftFactory $factory): void
{
$this->factory = $factory;
}
| public withValidateAuthState( ): self |
public function withValidateAuthState(): self
{
$new = clone $this;
$new->validateAuthState = true;
return $new;
}
| public withoutValidateAuthState( ): self |
public function withoutValidateAuthState(): self
{
$new = clone $this;
$new->validateAuthState = false;
return $new;
}
Signup or Login in order to comment.