PHPackages                             pasadinhas/oauth-4-laravel - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. pasadinhas/oauth-4-laravel

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

pasadinhas/oauth-4-laravel
==========================

OAuth Service Provider for Laravel 4

1.2.0(11y ago)019MITPHPPHP &gt;=5.3

Since Sep 18Pushed 11y ago1 watchersCompare

[ Source](https://github.com/pasadinhas/oauth-4-laravel)[ Packagist](https://packagist.org/packages/pasadinhas/oauth-4-laravel)[ Docs](https://github.com/pasadinhas/oauth-4-laravel)[ RSS](/packages/pasadinhas-oauth-4-laravel/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

OAuth wrapper for Laravel 4
===========================

[](#oauth-wrapper-for-laravel-4)

oauth-4-laravel is a simple laravel 4 service provider (wrapper) for [Pasadinhas/PHPoAuthLib](https://github.com/pasadinhas/PHPoAuthLib)which provides oAuth support in PHP 5.3+ and is very easy to integrate with any project which requires an oAuth client.

---

- [Supported services](#supported-services)
- [Installation](#installation)
- [Registering the Package](#registering-the-package)
- [Configuration](#configuration)
- [Usage](#usage)
- [Basic usage](#basic-usage)
- [More usage examples](#more-usage-examples)

Supported services
------------------

[](#supported-services)

The library supports both oAuth 1.x and oAuth 2.0 compliant services. A list of currently implemented services can be found below. If you implement a service, feel free to make a pull request with it!

Included service implementations:

- OAuth1
    - BitBucket
    - Etsy
    - FitBit
    - Flickr
    - Scoop.it!
    - Tumblr
    - Twitter
    - Xing
    - Yahoo
- OAuth2
    - Amazon
    - BitLy
    - Box
    - Dailymotion
    - Dropbox
    - Facebook
    - FenixEdu
    - Foursquare
    - GitHub
    - Google
    - Harvest
    - Heroku
    - Instagram
    - LinkedIn
    - Mailchimp
    - Microsoft
    - PayPal
    - Pocket
    - Reddit
    - RunKeeper
    - SoundCloud
    - Vkontakte
    - Yammer

To learn more about pasadinhas/PHPoAuthLib go [here](https://github.com/pasadinhas/PHPoAuthLib)

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

[](#installation)

Add oauth-4-laravel to your composer.json file (1.2.0 is the recomended version, feel free to use what you want/need):

```
"require": {
  "pasadinhas/oauth-4-laravel": "1.2.0"
}

```

Use composer to install this package.

```
$ composer update

```

### Registering the Package

[](#registering-the-package)

Register the service provider within the `providers` array found in `app/config/app.php`:

```
'providers' => array(
	// ...

	'LaravelOAuth\OAuthServiceProvider'
)
```

Add an alias within the `aliases` array found in `app/config/app.php`:

```
'aliases' => array(
	// ...

	'OAuth' => 'LaravelOAuth\Facade\OAuth',
)
```

Configuration
-------------

[](#configuration)

There are two ways to configure oauth-4-laravel. You can choose the most convenient way for you. You can use package config file which can be generated through command line by artisan (option 1) or you can simply create a config file called `oauth-4-laravel.php` in your `app\config\` directory (option 2).

#### Option 1

[](#option-1)

Create configuration file for package using artisan command

```
$ php artisan config:publish pasadinhas/oauth-4-laravel

```

#### Option 2

[](#option-2)

Create configuration file manually in config directory `app/config/oauth-4-laravel.php` and put there code from below.

```
return array(

	/*
	|--------------------------------------------------------------------------
	| oAuth Config
	|--------------------------------------------------------------------------
	*/

	/**
	 * Storage
	 */
	'storage' => 'Session',

	/**
	 * Consumers
	 */
	'consumers' => array(

		// Add your consumers here. Example:

		/**
		 * Facebook
		 */
		'Facebook' => array(
		    'client_id'     => '',
		    'client_secret' => '',
		    'scope'         => array(),
		),

	)

);
```

### Credentials

[](#credentials)

Add your credentials to `app/config/packages/pasadinhas/oauth-4-laravel/config.php` or `app/config/oauth-4-laravel.php` (depending on which option of configuration you choose)

The `Storage` attribute is optional and defaults to `Session`. [Other options](https://github.com/pasadinhas/PHPoAuthLib/tree/master/src/OAuth/Common/Storage).

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

Just follow the steps below and you will be able to get a [service class object](https://github.com/Lusitanian/PHPoAuthLib/tree/master/src/OAuth/OAuth2/Service) with this one rule:

```
$fb = OAuth::consumer('Facebook');
```

Optionally, add a second parameter with the URL which the service needs to redirect to. Otherwise it will look in the the config file for an option `redirect_url`. If that configuration is not present, it will redirect to the current URL.

```
$fb = OAuth::consumer('Facebook','http://url.to.redirect.to');
```

Usage examples
--------------

[](#usage-examples)

\###Facebook:

Configuration: Add your Facebook credentials to `app/config/packages/artdarek/oauth-4-laravel/config.php` or `app/config/oauth-4-laravel.php`:

```
'Facebook' => array(
    'client_id'     => 'Your Facebook client ID',
    'client_secret' => 'Your Facebook Client Secret',
    'scope'         => array('email','read_friendlists','user_online_presence'),
),
```

In your Controller use the following code:

```
/**
 * Login user with facebook
 *
 * @return void
 */

public function loginWithFacebook() {

	// get data from input
	$code = Input::get('code');

	// get fb service
	$fb = OAuth::consumer('Facebook');

	// check if code is valid

	// if code is provided get user data and sign in
	if (!empty($code)) {

		// This was a callback request from facebook, get the token
		$token = $fb->requestAccessToken($code);

		// Send a request with it
		$result = json_decode($fb->request('/me'), true);

		$message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
		echo $message. "";

		//Var_dump
		//display whole array().
		echo "";
		dd($result);

	}
	// if not ask for permission first
	else {
		// get fb authorization
		$url = $fb->getAuthorizationUri();

		// return to facebook login url
		 return Redirect::to((string) $url);
	}

}
```

\###Google:

Configuration: Add your Google credentials to `app/config/packages/artdarek/oauth-4-laravel/config.php`

```
'Google' => array(
    'client_id'     => 'Your Google client ID',
    'client_secret' => 'Your Google Client Secret',
    'scope'         => array('userinfo_email', 'userinfo_profile'),
),
```

In your Controller use the following code:

```
public function loginWithGoogle() {

	// get data from input
	$code = Input::get( 'code' );

	// get google service
	$googleService = OAuth::consumer( 'Google' );

	// check if code is valid

	// if code is provided get user data and sign in
	if ( !empty( $code ) ) {

		// This was a callback request from google, get the token
		$token = $googleService->requestAccessToken( $code );

		// Send a request with it
		$result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );

		$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
		echo $message. "";

		//Var_dump
		//display whole array().
		dd($result);

	}
	// if not ask for permission first
	else {
		// get googleService authorization
		$url = $googleService->getAuthorizationUri();

		// return to facebook login url
		return Redirect::to( (string)$url );
	}
}
```

\###Linkedin:

Configuration: Add your Linkedin credentials to `app/config/packages/artdarek/oauth-4-laravel/config.php`

```
'Linkedin' => array(
    'client_id'     => 'Your Linkedin API ID',
    'client_secret' => 'Your Linkedin API Secret',
),
```

In your Controller use the following code:

```
 public function loginWithLinkedin() {

        // get data from input
        $code = Input::get( 'code' );

        $linkedinService = OAuth::consumer( 'Linkedin' );

        if ( !empty( $code ) ) {

            // This was a callback request from linkedin, get the token
            $token = $linkedinService->requestAccessToken( $code );
            // Send a request with it. Please note that XML is the default format.
            $result = json_decode($linkedinService->request('/people/~?format=json'), true);

            // Show some of the resultant data
            echo 'Your linkedin first name is ' . $result['firstName'] . ' and your last name is ' . $result['lastName'];

            //Var_dump
            //display whole array().
            dd($result);

        }// if not ask for permission first
        else {
            // get linkedinService authorization
            $url = $linkedinService->getAuthorizationUri(array('state'=>'DCEEFWF45453sdffef424'));

            // return to linkedin login url
            return Redirect::to( (string)$url );
        }

    }
```

\###FenixEdu:

Configuration: Add your FenixEdu credentials to `app/config/packages/artdarek/oauth-4-laravel/config.php` or `app/config/oauth-4-laravel.php`:

```
'FenixEdu' => array(
    'client_id'         => 'Your FenixEdu Client ID',
    'client_secret'     => 'Your FenixEdu Client Secret',
    'redirect_url'      => 'Your FenixEdu redirect URL',
    'automatic_refresh' => true, // if you want to use the refresh token automaticly
),
```

In your Controller use the following code:

```
/**
 * Login user with FenixEdu
 *
 * @return void
 */

public function loginWithFenixEdu() {

	// get data from input
	$code = Input::get('code');

	// get FenixEdu service
	$fenix = OAuth::consumer('FenixEdu');

	// check if code is valid

	// if code is provided get user data and sign in
	if (!empty($code)) {

		// This was a callback request from facebook, get the token
		$token = $fenix->requestAccessToken($code);

		// Send a request with it
		$result = json_decode($fenix->request('/person'), true);

		$message = 'Your FenixEdu user is: ' . $result['username'] . ' and your name is ' . $result['name'];
		echo $message. "";

		//Var_dump
		//display whole array().
		echo "";
		dd($result);

	}
	// if not ask for permission first
	else {
		// get FenixEdu authorization
		$url = $fenix->getAuthorizationUri();

		// return to FenixEdu login url
		 return Redirect::to((string) $url);
	}

}
```

### More usage examples:

[](#more-usage-examples)

For examples go [here](https://github.com/pasadinhas/PHPoAuthLib/tree/master/examples)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~53 days

Recently: every ~66 days

Total

7

Last Release

4299d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/91f7fe11972214893f1ac7bfe987021e018f9216d44af4381032682ea1d28478?d=identicon)[pasadinhas](/maintainers/pasadinhas)

---

Top Contributors

[![artdarek](https://avatars.githubusercontent.com/u/1362351?v=4)](https://github.com/artdarek "artdarek (32 commits)")[![pasadinhas](https://avatars.githubusercontent.com/u/4405254?v=4)](https://github.com/pasadinhas "pasadinhas (17 commits)")[![felipepodesta](https://avatars.githubusercontent.com/u/102604?v=4)](https://github.com/felipepodesta "felipepodesta (3 commits)")[![brianmuse](https://avatars.githubusercontent.com/u/548885?v=4)](https://github.com/brianmuse "brianmuse (2 commits)")[![mohitmamoria](https://avatars.githubusercontent.com/u/2756694?v=4)](https://github.com/mohitmamoria "mohitmamoria (2 commits)")[![samvasko](https://avatars.githubusercontent.com/u/2674600?v=4)](https://github.com/samvasko "samvasko (1 commits)")[![SCIF](https://avatars.githubusercontent.com/u/671925?v=4)](https://github.com/SCIF "SCIF (1 commits)")[![shrink](https://avatars.githubusercontent.com/u/349689?v=4)](https://github.com/shrink "shrink (1 commits)")[![strongwazz](https://avatars.githubusercontent.com/u/911315?v=4)](https://github.com/strongwazz "strongwazz (1 commits)")[![bryanisimo](https://avatars.githubusercontent.com/u/164136?v=4)](https://github.com/bryanisimo "bryanisimo (1 commits)")[![joshuaziering](https://avatars.githubusercontent.com/u/1530131?v=4)](https://github.com/joshuaziering "joshuaziering (1 commits)")[![nicolas-lescop](https://avatars.githubusercontent.com/u/1667009?v=4)](https://github.com/nicolas-lescop "nicolas-lescop (1 commits)")[![PeeHaa](https://avatars.githubusercontent.com/u/1330296?v=4)](https://github.com/PeeHaa "PeeHaa (1 commits)")

---

Tags

phplaraveloauthLusitanian

### Embed Badge

![Health badge](/badges/pasadinhas-oauth-4-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/pasadinhas-oauth-4-laravel/health.svg)](https://phpackages.com/packages/pasadinhas-oauth-4-laravel)
```

###  Alternatives

[artdarek/oauth-4-laravel

OAuth Service Provider for Laravel 4

693504.8k](/packages/artdarek-oauth-4-laravel)[oriceon/oauth-5-laravel

OAuth Service Provider for Laravel 5

1851.5M](/packages/oriceon-oauth-5-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
