PHPackages                             effectra/third-party - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. effectra/third-party

ActiveLibrary[HTTP &amp; Networking](/categories/http)

effectra/third-party
====================

The Effectra ThirdParty package.

v1.0.0(3y ago)1271MITPHP

Since Jun 19Pushed 2y agoCompare

[ Source](https://github.com/effectra/third-party)[ Packagist](https://packagist.org/packages/effectra/third-party)[ RSS](/packages/effectra-third-party/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

Effectra ThirdParty Library
===========================

[](#effectra-thirdparty-library)

Effectra\\ThirdParty is a PHP library that provides OAuth configuration and functionality for various third-party platforms such as LinkedIn, GitHub, Facebook, and Google. It simplifies the process of integrating with these platforms and accessing user data through OAuth authentication.

Features
--------

[](#features)

- Simplified OAuth configuration and authentication for third-party platforms.
- Easy retrieval of access tokens and user information.
- Supports multiple popular platforms like LinkedIn, GitHub, Facebook, and Google.

Installation
------------

[](#installation)

You can install the Effectra\\ThirdParty library via Composer. Run the following command in your project directory:

```
composer require effectra/third-party
```

Usage
-----

[](#usage)

### LinkedIn

[](#linkedin)

To use the LinkedIn OAuth functionality, follow these steps:

1. Create an instance of the `LinkedIn` class by providing your LinkedIn client ID, client secret, and optional redirect URL and scopes.

```
use Effectra\ThirdParty\LinkedIn;

$linkedin = new LinkedIn('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['r_liteprofile', 'r_emailaddress']);
```

2. Generate the authorization URL to redirect the user for authentication:

```
$authUrl = $linkedin->getAuthURL();
```

3. Redirect the user to the generated authorization URL. After successful authentication, LinkedIn will redirect the user back to the specified redirect URL with an authorization code.
4. Exchange the authorization code for an access token:

```
$code = $_GET['code']; // The authorization code obtained from the LinkedIn redirect
$accessToken = $linkedin->getAccessToken($code);
```

5. Use the access token to retrieve user information:

```
$user = $linkedin->getUser($accessToken);
```

### GitHub

[](#github)

To use the GitHub OAuth functionality, follow these steps:

1. Create an instance of the `GitHub` class by providing your GitHub client ID, client secret, and optional redirect URL and scopes.

```
use Effectra\ThirdParty\GitHub;

$github = new GitHub('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['user']);
```

2. Generate the authorization URL to redirect the user for authentication:

```
$authUrl = $github->getAuthURL();
```

3. Redirect the user to the generated authorization URL. After successful authentication, GitHub will redirect the user back to the specified redirect URL with an authorization code.
4. Exchange the authorization code for an access token:

```
$code = $_GET['code']; // The authorization code obtained from the GitHub redirect
$accessToken = $github->getAccessToken($code);
```

5. Use the access token to retrieve user information:

```
$user = $github->getUser($accessToken);
```

### Facebook

[](#facebook)

To use the Facebook OAuth functionality, follow these steps:

1. Create an instance of the `Facebook` class by providing your Facebook client ID, client secret, and optional redirect URL and scopes.

```
use Effectra\ThirdParty\Facebook;

$facebook = new Facebook('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['email']);
```

2. Generate the authorization URL to redirect the user for authentication:

```
$authUrl = $facebook->getAuthURL();
```

3. Redirect the user to the generated authorization URL. After successful authentication, Facebook will redirect the user back to the specified redirect URL with an authorization code.
4. Exchange the authorization code for an access token:

```
$code = $_GET['code']; // The authorization code obtained from the Facebook redirect
$accessToken = $facebook->getAccessToken($code);
```

5

. Use the access token to retrieve user information:

```
$user = $facebook->getUser($accessToken);
```

### Google

[](#google)

To use the Google OAuth functionality, follow these steps:

1. Create an instance of the `Google` class by providing your Google client ID, client secret, and optional redirect URL and scopes.

```
use Effectra\ThirdParty\Google;

$google = new Google('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URL', ['profile', 'email']);
```

2. Generate the authorization URL to redirect the user for authentication:

```
$authUrl = $google->getAuthURL();
```

3. Redirect the user to the generated authorization URL. After successful authentication, Google will redirect the user back to the specified redirect URL with an authorization code.
4. Exchange the authorization code for an access token:

```
$code = $_GET['code']; // The authorization code obtained from the Google redirect
$accessToken = $google->getAccessToken($code);
```

5. Use the access token to retrieve user information:

```
$user = $google->getUser($accessToken);
```

OAuthServiceInterface
---------------------

[](#oauthserviceinterface)

The `OAuthServiceInterface` is an interface that defines the contract for an OAuth service. It provides methods for retrieving configuration, authorization URL, access token, and user data from an OAuth service.

### Usage

[](#usage-1)

To use this interface, you need to create a class that implements it and provides the necessary functionality. Here's an example of how you can implement the `OAuthServiceInterface`:

```
