Facebook Provider for OAuth 2.0 Client

Facebook Provider for OAuth 2.0 Client supported following version

  • PHP 7.3

  • PHP 7.4

  • PHP 8.0 and above

If your Php version is below above version, then you could consider to use Facebook SDK for PHP (v5) which is released by META official.

However, Facebook SDK for PHP (v5) had not update since 2020, and it is no more support PHP version 8 and above. But it stil best selection if you are using Php version 5.

Installation

Composer

You can use Composer or simply Download the Release. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

composer require league/oauth2-client
composer require league/oauth2-facebook

Finally, be sure to include the autoloader at your php coding :

require_once 'vendor/autoload.php';

Facebook Developer Setup

Open Facebook Developer, Select the [Create App] on the right upper corner and create a new app.

Select [Other] then select [Consumer]

Add an [App name]

Find the Facebook Login at the third card and click the [Set Up] button

Select [Web]

Add the site URL, click [Save] and keep click [Continue] or [Save] until [Step 5 Next Steps]

Go to [Setting] under the [Facebook Login] from your left panel, and add your [Valid Oauth Redirect URLs]. [Save Changes] after done

After then, select [Basic] under [App settings] at left side banner and fill in the [App domain], [Privacy Policy URL] and [Contact Email]

Copy down the [App ID] and [App secret]. It will be useful at code later on.

Also, scrolling down to below and click [+ Add platform], select [Website] and fill in the [Site URL] which is same with your [Valid Oauth Redirect URLs]

Remember to made your App Mode to [Live] mode

Implementation on Your Website

login_fb.php

replace the clientID and clientSecret to your [client ID] and [Client Secret]

button.php

Create a login button to header to login_fb.php

PHP

Html

Last updated