Class yii\authclient\clients\Facebook
Inheritance | yii\authclient\clients\Facebook » yii\authclient\OAuth2 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\authclient\ClientInterface, yii\base\Configurable |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/clients/Facebook.php |
Facebook allows authentication via Facebook OAuth.
In order to use Facebook OAuth you must register your application at https://developers.facebook.com/apps. Add an app. In "Settings" -> "Basic" specify "App Domains". There you can obtain ID and Secret values to put into config. In "Products" press "+" and add "Facebook Login". In its settings make sure you enabled "Web OAuth Login" and specify "Valid OAuth Redirect URIs" as "https://example.com/auth?authclient=facebook".
Example application configuration:
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => 'facebook_client_id',
'clientSecret' => 'facebook_client_secret',
],
],
]
// ...
]
See also:
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$accessToken | yii\authclient\OAuthToken | Auth token instance. Note that the type of this property differs in getter and setter. See getAccessToken() and setAccessToken() for details. | yii\authclient\BaseOAuth |
$apiBaseUrl | string | API base URL. | yii\authclient\clients\Facebook |
$attributeNames | array | List of attribute names, which should be requested from API to initialize user attributes. | yii\authclient\clients\Facebook |
$authUrl | string | Authorize URL. | yii\authclient\clients\Facebook |
$autoExchangeAccessToken | boolean | Whether to automatically upgrade short-live (2 hours) access token to long-live (60 days) one, after fetching it. | yii\authclient\clients\Facebook |
$autoRefreshAccessToken | boolean | Whether to automatically perform 'refresh access token' request on expired access token. | yii\authclient\clients\Facebook |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. | yii\base\Component |
$clientAuthCodeUrl | string | URL endpoint for the client auth code generation. | yii\authclient\clients\Facebook |
$clientId | string | OAuth client ID. | yii\authclient\OAuth2 |
$clientSecret | string | OAuth client secret. | yii\authclient\OAuth2 |
$enablePkce | boolean | Whether to enable proof key for code exchange (PKCE) support and add
a code_challenge and code_verifier to the auth request. |
yii\authclient\OAuth2 |
$httpClient | yii\httpclient\Client | Internal HTTP client. Note that the type of this property differs in getter and setter. See getHttpClient() and setHttpClient() for details. | yii\authclient\BaseClient |
$id | string | Service id. | yii\authclient\BaseClient |
$name | string | Service name. | yii\authclient\BaseClient |
$normalizeUserAttributeMap | array | Normalize user attribute map. | yii\authclient\BaseClient |
$parametersToKeepInReturnUrl | array | List of the parameters to keep in default return url. | yii\authclient\BaseOAuth |
$requestOptions | array | HTTP request options. | yii\authclient\BaseClient |
$returnUrl | string | Return URL. | yii\authclient\BaseOAuth |
$scope | string | Auth request scope. | yii\authclient\clients\Facebook |
$signatureMethod | yii\authclient\signature\BaseMethod | Signature method instance. Note that the type of this property differs in getter and setter. See getSignatureMethod() and setSignatureMethod() for details. | yii\authclient\BaseOAuth |
$stateStorage | yii\authclient\StateStorageInterface | Stage storage. Note that the type of this property differs in getter and setter. See getStateStorage() and setStateStorage() for details. | yii\authclient\BaseClient |
$title | string | Service title. | yii\authclient\BaseClient |
$tokenUrl | string | Token request URL endpoint. | yii\authclient\clients\Facebook |
$userAttributes | array | List of user attributes. | yii\authclient\BaseClient |
$validateAuthState | boolean | Whether to use and validate auth 'state' parameter in authentication flow. | yii\authclient\OAuth2 |
$version | string | Protocol version. | yii\authclient\BaseOAuth |
$viewOptions | array | View options in format: optionName => optionValue. | yii\authclient\BaseClient |
Public Methods
Protected Methods
Property Details
API base URL. This field will be used as yii\httpclient\Client::$baseUrl value of $httpClient. Note: changing this property will take no effect after $httpClient is instantiated.
List of attribute names, which should be requested from API to initialize user attributes.
Authorize URL.
Whether to automatically upgrade short-live (2 hours) access token to long-live (60 days) one, after fetching it.
See also exchangeToken().
Whether to automatically perform 'refresh access token' request on expired access token.
URL endpoint for the client auth code generation.
See also:
Auth request scope.
Token request URL endpoint.
Method Details
Applies access token to the HTTP request instance.
public void applyAccessTokenToRequest ( $request, $accessToken ) | ||
$request | yii\httpclient\Request | HTTP request instance. |
$accessToken | yii\authclient\OAuthToken | Access token instance. |
Generates service name.
protected string defaultName ( ) | ||
return | string | Service name. |
---|
Generates service title.
protected string defaultTitle ( ) | ||
return | string | Service title. |
---|
Returns the default $viewOptions value.
Particular client may override this method in order to provide specific default view options.
protected array defaultViewOptions ( ) | ||
return | array | List of default $viewOptions |
---|
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.
See also https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension.
public yii\authclient\OAuthToken exchangeAccessToken ( yii\authclient\OAuthToken $token ) | ||
$token | yii\authclient\OAuthToken | Short-live access token. |
return | yii\authclient\OAuthToken | Long-live access token. |
---|
Fetches access token from authorization code.
public yii\authclient\OAuthToken fetchAccessToken ( $authCode, array $params = [] ) | ||
$authCode | string | Authorization code, usually comes at GET parameter 'code'. |
$params | array | Additional request params. |
return | yii\authclient\OAuthToken | Access token. |
---|---|---|
throws | yii\web\HttpException | on invalid auth state in case enableStateValidation is enabled. |
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:
public yii\authclient\OAuthToken fetchClientAccessToken ( $authCode, array $params = [] ) | ||
$authCode | string | Client auth code. |
$params | array | |
return | yii\authclient\OAuthToken | Long-live client-specific access 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:
public string fetchClientAuthCode ( yii\authclient\OAuthToken $token = null, $params = [] ) | ||
$token | yii\authclient\OAuthToken|null | Access token, if not set $accessToken will be used. |
$params | array | Additional request params. |
return | string | Client auth code. |
---|
Initializes authenticated user attributes.
protected array initUserAttributes ( ) | ||
return | array | Auth user attributes. |
---|