PHPackages                             mmanos/laravel-social - 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. mmanos/laravel-social

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

mmanos/laravel-social
=====================

A social login package for Laravel 4.

v1.0.5(11y ago)556.8k11[9 issues](https://github.com/mmanos/laravel-social/issues)[2 PRs](https://github.com/mmanos/laravel-social/pulls)MITPHPPHP &gt;=5.4.0

Since Sep 8Pushed 10y ago5 watchersCompare

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

READMEChangelog (6)Dependencies (2)Versions (7)Used By (0)

Social Login Package for Laravel 4
==================================

[](#social-login-package-for-laravel-4)

This package is a Laravel 4 service provider for [Lusitanian/PHPoAuthLib](https://github.com/Lusitanian/PHPoAuthLib) which provides oAuth support in PHP 5.3+ and is very easy to integrate with any project which requires an oAuth client.

In addition, you may take advantage of the optional controller and model to make it very easy to:

- Log in with a social provider
- Connect an existing user record with a social provider
- Perform requests against the social provider API with each user's unique access token

Supported Services
------------------

[](#supported-services)

See the documentation for Lusitanian/PHPoAuthLib for the [list of supported services](https://github.com/Lusitanian/PHPoAuthLib#included-service-implementations).

Installation Via Composer
-------------------------

[](#installation-via-composer)

Add this to your composer.json file, in the require object:

```
"mmanos/laravel-social": "dev-master"
```

After that, run composer install to install the package.

Add the service provider to `app/config/app.php`, within the `providers` array.

```
'providers' => array(
	// ...
	'Mmanos\Social\SocialServiceProvider',
)
```

Add a class alias to `app/config/app.php`, within the `aliases` array.

```
'aliases' => array(
	// ...
	'Social' => 'Mmanos\Social\Facades\Social',
)
```

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

[](#configuration)

Publish the default config file to your application so you can make modifications.

```
$ php artisan config:publish mmanos/laravel-social
```

Add your service provider credentials to the published config file: `app/config/packages/mmanos/laravel-social/config.php`

Basic Usage
-----------

[](#basic-usage)

Obtain a service class object for a provider.

```
$service = Social::service('facebook');
```

Optionally, add a second parameter with the URL which the service needs to redirect to, otherwise it will redirect to the current URL.

```
$service = Social::service('facebook', 'http://example.com');
```

Redirect the user to the oAuth log in page for a provider.

```
return Redirect::to((string) $service->getAuthorizationUri());
```

For examples of how to integrate with a specific provider, [see here](https://github.com/Lusitanian/PHPoAuthLib/tree/master/examples).

Using The Provided Controller And Model
---------------------------------------

[](#using-the-provided-controller-and-model)

For added convenience, use the built-in controller and model to easily log in or connect with a social provider account.

#### Requirements

[](#requirements)

This implementation is fairly opinionated and assumes that you want to allow your users to log in or sign up seamlessly with their existing social provider account and associate that social provider account with an existing user record.

It has these requirements:

- You have an existing user record with a numeric primary key
- You are using the Laravel authentication system
- You have the Laravel session system enabled
- You have an app key defined in your config/app.php file so the Crypt class can be used to encrypt the access tokens

#### Migration

[](#migration)

Publish and run the database migrations for this package. This will create a `user_providers` table.

```
$ php artisan migrate:publish mmanos/laravel-social
$ php artisan migrate
```

> **Note:** You can change the default table name used to store the user provider information by changing the value of the `table` key in the config file.

#### Model Setup

[](#model-setup)

Add the SocialTrait to your User model definition.

```
use Mmanos\Social\SocialTrait;

class User extends Eloquent
{
	use SocialTrait;

}
```

#### Social Login Flow

[](#social-login-flow)

Simply create a link to the built-in controller to initiate a log in flow. The user will be redirected to the provider login page before they return to your website.

If an existing user is already linked to the provider account, they will be logged in as that user.

If an existing user is not found for the provider account, a new user record will be created and then a link to the provider account will be made before they are logged in as that user.

```

	Log in with Twitter

```

To customize where the user is redirected to after the log in flow, add `onsuccess` and `onerror` parameters.

```

	Log in with Twitter

```

> **Note:** The default redirect location is to the `referer` header. Otherwise `/`.

#### Connecting A Social Account Flow

[](#connecting-a-social-account-flow)

You can also associate a social provider account to an existing user if they are already logged in.

```

	Connect Your Twitter Account

```

> **Note:** This action also supports the `onsuccess` and `onerror` parameters.

#### Working With Users And Providers

[](#working-with-users-and-providers)

You can fetch all providers linked to a user.

```
$providers = Auth::user()->providers;
```

You can check to see if a user is connected to a given provider.

```
if (Auth::user()->hasProvider('twitter')) {
	//
}
```

You can fetch a single provider instance for a user.

```
$provider = Auth::user()->provider('twitter');
```

This package stores an encrypted version of the access\_token for each user provider. That way you can easily make API calls to the provider service on behalf of the user.

```
$result = Auth::user()->provider('twitter')->request('account/verify_credentials.json');
```

> **Note:** Keep in mind it is possible for an access\_token to expire. You can refresh a user's access\_token by initiating a redirect to the `getConnect` action in the controller.

#### Create User Logic

[](#create-user-logic)

If you want to customize the logic used to create a user during the social login flow, modify the `create_user` key in the config file.

```
'create_user' => function ($data) {
	$user = new User;
	$user->email = array_get($data, 'email');
	$user->password = Hash::make(Str::random());
	$user->location = array_get($data, 'location'); // Only passed by certain providers.
	$user->save();

	return $user->id;
},
```

> **Note:** Make sure to return a numeric primary key when finished.

> **Note:** The information passed in the `$data` parameter is the data returned from the `fetch_user_info` functions for each provider in the config file.

#### Provider User Information

[](#provider-user-information)

To customize which data you want to retrieve from a social provider account, modify the `fetch_user_info` key for each provider in the config file.

```
	'fetch_user_info' => function ($service) {
		$result = json_decode($service->request('account/verify_credentials.json'), true);
		return array(
			'id'         => array_get($result, 'id'),
			'email'      => null,
			'first_name' => array_get(explode(' ', array_get($result, 'name')), 0),
			'last_name'  => array_get(explode(' ', array_get($result, 'name')), 1)
			'location'   => array_get($result, 'location'),
		);
	},
```

> **Note:** This function also allows you to normalize the user data returned by each of the social providers by mapping their fields to fields you want to store in your user record.

#### New User Validation

[](#new-user-validation)

You can configure the social login flow to validate the user information returned by the social provider. This way you can ensure that all of the data you require for a new user is properly obtained and in the correct format.

To customize the validation rules, modify the `user_validation` key in the config file.

```
'user_validation' => array(
	'email'      => 'required|email',
	'first_name' => 'required',
	'location'   => 'required',
),
```

> **Note:** You may also declare a closure function to create and return a Validator instance for greater flexibility.

Social Buttons
--------------

[](#social-buttons)

This package provides some convenient css that allows you to create nice social buttons. It is built for use with the [Twitter Bootstrap](https://github.com/twbs/bootstrap) and [Font Awesome](http://fontawesome.io/) frameworks.

#### Publish The Assets

[](#publish-the-assets)

Publish the public assets for this package.

```
$ php artisan asset:publish mmanos/laravel-social
```

#### Include The Assets

[](#include-the-assets)

```
{{ HTML::style('/packages/mmanos/laravel-social/css/socialbuttons.css') }}
```

#### Building Buttons

[](#building-buttons)

```

	 Log in with Twitter

```

[See here](https://github.com/lipis/bootstrap-social#available-classes) for a list of supported class names.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 86.7% 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 ~16 days

Total

6

Last Release

4183d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/972055?v=4)[Mark Manos](/maintainers/mmanos)[@mmanos](https://github.com/mmanos)

---

Top Contributors

[![mmanos](https://avatars.githubusercontent.com/u/972055?v=4)](https://github.com/mmanos "mmanos (13 commits)")[![dmyers](https://avatars.githubusercontent.com/u/207171?v=4)](https://github.com/dmyers "dmyers (1 commits)")[![ldin](https://avatars.githubusercontent.com/u/5782841?v=4)](https://github.com/ldin "ldin (1 commits)")

---

Tags

laraveloauthprovidersloginsocial

### Embed Badge

![Health badge](/badges/mmanos-laravel-social/health.svg)

```
[![Health](https://phpackages.com/badges/mmanos-laravel-social/health.svg)](https://phpackages.com/packages/mmanos-laravel-social)
```

###  Alternatives

[socialiteproviders/manager

Easily add new or override built-in providers in Laravel Socialite.

42442.0M544](/packages/socialiteproviders-manager)[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[mad-web/laravel-social-auth

Easy social auth integration with a lot of available providers

516.7k](/packages/mad-web-laravel-social-auth)[vinelab/social-auth

101.3k1](/packages/vinelab-social-auth)

PHPackages © 2026

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