PHPackages                             adamwathan/eloquent-oauth-l5 - 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. adamwathan/eloquent-oauth-l5

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

adamwathan/eloquent-oauth-l5
============================

Stupid simple OAuth authentication with Laravel and Eloquent

v0.5.2(9y ago)21752.2k48[1 issues](https://github.com/adamwathan/eloquent-oauth-l5/issues)2MITPHPPHP &gt;=5.5.0

Since May 14Pushed 8y ago16 watchersCompare

[ Source](https://github.com/adamwathan/eloquent-oauth-l5)[ Packagist](https://packagist.org/packages/adamwathan/eloquent-oauth-l5)[ RSS](/packages/adamwathan-eloquent-oauth-l5/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (13)Used By (2)

> **Important: This package is not actively maintained.** For bug fixes and new features, please fork.

Eloquent OAuth L5
=================

[](#eloquent-oauth-l5)

[![This Project Has Been Deprecated.](https://camo.githubusercontent.com/3ae650fc7228648d06b62681ce7c397abe96e1677840b72cc69c336a0de863c6/687474703a2f2f7777772e7265706f7374617475732e6f72672f6261646765732f302e312e302f6162616e646f6e65642e737667)](http://www.repostatus.org/#abandoned)

> Note: Use the [Laravel 4 package](https://github.com/adamwathan/eloquent-oauth-l4) if you are using Laravel 4.

Eloquent OAuth is a package for Laravel 5 designed to make authentication against various OAuth providers *ridiculously* brain-dead simple. Specify your client IDs and secrets in a config file, run a migration and after that it's just two method calls and you have OAuth integration.

#### Video Walkthrough

[](#video-walkthrough)

[![Screenshot](https://cloud.githubusercontent.com/assets/4323180/6274884/ac824c48-b848-11e4-8e4d-531e15f76bc0.png)](https://vimeo.com/120085196)

#### Basic example

[](#basic-example)

```
// Redirect to Facebook for authorization
Route::get('facebook/authorize', function() {
    return SocialAuth::authorize('facebook');
});

// Facebook redirects here after authorization
Route::get('facebook/login', function() {

    // Automatically log in existing users
    // or create a new user if necessary.
    SocialAuth::login('facebook');

    // Current user is now available via Auth facade
    $user = Auth::user();

    return Redirect::intended();
});
```

#### Supported Providers

[](#supported-providers)

- Facebook
- GitHub
- Google
- LinkedIn
- Instagram
- Soundcloud

> Feel free to open an issue if you would like support for a particular provider, or even better, submit a pull request.

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

[](#installation)

#### Add this package using Composer

[](#add-this-package-using-composer)

From the command line inside your project directory, simply type:

`composer require adamwathan/eloquent-oauth-l5`

#### Update your config

[](#update-your-config)

Add the service provider to the `providers` array in `config/app.php`:

```
'providers' => [
    // ...
    AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider::class,
    // ...
]
```

Add the facade to the `aliases` array in `config/app.php`:

```
'aliases' => [
    // ...
    'SocialAuth' => AdamWathan\EloquentOAuth\Facades\OAuth::class,
    // ...
]
```

#### Publish the package configuration

[](#publish-the-package-configuration)

Publish the configuration file and migrations by running the provided console command:

`php artisan eloquent-oauth:install`

Next, re-migrate your database:

`php artisan migrate`

> If you need to change the name of the table used to store OAuth identities, you can do so in the `eloquent-oauth` config file.

#### Configure the providers

[](#configure-the-providers)

Update your app information for the providers you are using in `config/eloquent-oauth.php`:

```
'providers' => [
    'facebook' => [
        'client_id' => '12345678',
        'client_secret' => 'y0ur53cr374ppk3y',
        'redirect_uri' => 'https://example.com/facebook/login'),
        'scope' => [],
    ]
]
```

> Each provider is preconfigured with the scope necessary to retrieve basic user information and the user's email address, so the scope array can usually be left empty unless you need specific additional permissions. Consult the provider's API documentation to find out what permissions are available for the various services.

All done!

> Eloquent OAuth is designed to integrate with Laravel's Eloquent authentication driver, so be sure you are using the `eloquent` driver in `app/config/auth.php`. You can define your actual `User` model however you choose and add whatever behavior you need, just be sure to specify the model you are using with its fully qualified namespace in `app/config/auth.php` as well.

#### Custom providers

[](#custom-providers)

If you'd like to register a provider for a service that isn't supported out of the box, you can do so by first specifying the configuration needed for that provider in your `config/eloquent-oauth.php`:

```
// config/eloquent-oauth.php
return [
    'model' => User::class,
    'table' => 'oauth_identities',
    'providers' => [
        'facebook' => [ /* ... */],
        'google' => [ /* ... */],
        'gumroad' => [
            'client_id' => env('GUMROAD_CLIENT_ID'),
            'client_secret' => env('GUMROAD_CLIENT_SECRET'),
            'redirect_uri' => env('GUMROAD_REDIRECT_URI'),
            'scope' => ['view_sales'],
        ],
    ],
];
```

Then specify which class should be used for that provider by extending `EloquentOAuthServiceProvider` with your own implementation that maps the provider name to a provider class:

```
class MySocialAuthServiceProvider extends EloquentOAuthServiceProvider
{
    protected function getProviderLookup()
    {
        // Merge the default providers if you like, or override entirely
        // to skip loading those providers completely.
        return array_merge($this->providerLookup, [
            'gumroad' => GumroadProvider::class
        ]);
    }
}
```

> Don't forget to use your extension of the provider in `config/app.php` instead of the one supplied by the package.

If your provider follows the same `__construct($config, $httpClient, $request)` parameter signature that the default providers use, you're done.

If not, make sure you bind your provider to the IOC container in another provider, and the package will make sure to fetch the implementation from the container instead of trying to construct it itself.

To get an idea of how the providers work, take a look at how the packaged providers are implemented:

-
-
-
-
-
-

Usage
-----

[](#usage)

Authentication against an OAuth provider is a multi-step process, but I have tried to simplify it as much as possible.

### Authorizing with the provider

[](#authorizing-with-the-provider)

First you will need to define the authorization route. This is the route that your "Login" button will point to, and this route redirects the user to the provider's domain to authorize your app. After authorization, the provider will redirect the user back to your second route, which handles the rest of the authentication process.

To authorize the user, simply return the `SocialAuth::authorize()` method directly from the route.

```
Route::get('facebook/authorize', function() {
    return SocialAuth::authorize('facebook');
});
```

### Authenticating within your app

[](#authenticating-within-your-app)

Next you need to define a route for authenticating against your app with the details returned by the provider.

For basic cases, you can simply call `SocialAuth::login()` with the provider name you are authenticating with. If the user rejected your application, this method will throw an `ApplicationRejectedException` which you can catch and handle as necessary.

The `login` method will create a new user if necessary, or update an existing user if they have already used your application before.

Once the `login` method succeeds, the user will be authenticated and available via `Auth::user()` just like if they had logged in through your application normally.

```
use SocialNorm\Exceptions\ApplicationRejectedException;
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;

Route::get('facebook/login', function() {
    try {
        SocialAuth::login('facebook');
    } catch (ApplicationRejectedException $e) {
        // User rejected application
    } catch (InvalidAuthorizationCodeException $e) {
        // Authorization was attempted with invalid
        // code,likely forgery attempt
    }

    // Current user is now available via Auth facade
    $user = Auth::user();

    return Redirect::intended();
});
```

If you need to do anything with the newly created user, you can pass an optional closure as the second argument to the `login` method. This closure will receive the `$user` instance and a `ProviderUserDetails`object that contains basic information from the OAuth provider, including:

- User ID
- Nickname
- Full Name
- Email
- Avatar URL
- Access Token

```
SocialAuth::login('facebook', function($user, $details) {
    $user->nickname = $details->nickname;
    $user->name = $details->full_name;
    $user->profile_image = $details->avatar;
    $user->save();
});
```

> Note: The Instagram and Soundcloud APIs do not allow you to retrieve the user's email address, so unfortunately that field will always be `null` for those providers.

### Advanced: Storing additional data

[](#advanced-storing-additional-data)

Remember: One of the goals of the Eloquent OAuth package is to normalize the data received across all supported providers, so that you can count on those specific data items (explained above) being available in the `$details` object.

But, each provider offers its own sets of additional data. If you need to access or store additional data beyond the basics of what Eloquent OAuth's default `ProviderUserDetails` object supplies, you need to do two things:

1. Request it from the provider, by extending its scope:

    Say for example we want to collect the user's gender when they login using Facebook.

    In the `config/eloquent-oauth.php` file, set the `[scope]` in the `facebook` provider section to include the `public_profile` scope, like this:

    ```
       'scope' => ['public_profile'],
    ```

> For available scopes with each provider, consult that provider's API documentation.

> Note: By increasing the scope you will be asking the user to grant access to additional information. They will be informed of the scopes you're requesting. If you ask for too much unnecessary data, they may refuse. So exercise restraint when requesting additional scopes.

2. Now where you do your `SocialAuth::login`, store the to your `$user` object by accessing the `$details->raw()['KEY']` data:

```
       SocialAuth::login('facebook', function($user, $details) (
           $user->gender = $details->raw()['gender'];
           $user->save();
       });
```

> Tip: You can see what the available keys are by testing with `dd($details->raw());` inside that same closure.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.5% 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 ~69 days

Recently: every ~99 days

Total

10

Last Release

3395d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.4.0

v0.3.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3fb69ca14ca0266d852fc2678a6e00db1b3dbf209db9ecfdee3fa9ac913feed?d=identicon)[adamwathan](/maintainers/adamwathan)

---

Top Contributors

[![adamwathan](https://avatars.githubusercontent.com/u/4323180?v=4)](https://github.com/adamwathan "adamwathan (185 commits)")[![drbyte](https://avatars.githubusercontent.com/u/404472?v=4)](https://github.com/drbyte "drbyte (3 commits)")[![knvpk](https://avatars.githubusercontent.com/u/6078669?v=4)](https://github.com/knvpk "knvpk (3 commits)")[![colindecarlo](https://avatars.githubusercontent.com/u/682860?v=4)](https://github.com/colindecarlo "colindecarlo (2 commits)")[![syphernl](https://avatars.githubusercontent.com/u/639906?v=4)](https://github.com/syphernl "syphernl (2 commits)")[![KroniK907](https://avatars.githubusercontent.com/u/4690564?v=4)](https://github.com/KroniK907 "KroniK907 (2 commits)")[![AndrewCarterUK](https://avatars.githubusercontent.com/u/6486835?v=4)](https://github.com/AndrewCarterUK "AndrewCarterUK (1 commits)")[![schmitzc](https://avatars.githubusercontent.com/u/10464?v=4)](https://github.com/schmitzc "schmitzc (1 commits)")[![cmgmyr](https://avatars.githubusercontent.com/u/4693481?v=4)](https://github.com/cmgmyr "cmgmyr (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adamwathan-eloquent-oauth-l5/health.svg)

```
[![Health](https://phpackages.com/badges/adamwathan-eloquent-oauth-l5/health.svg)](https://phpackages.com/packages/adamwathan-eloquent-oauth-l5)
```

###  Alternatives

[josiasmontag/laravel-recaptchav3

Recaptcha V3 for Laravel package

2641.6M2](/packages/josiasmontag-laravel-recaptchav3)[rahul900day/laravel-captcha

Different types of Captcha implementation for Laravel Application.

10715.9k](/packages/rahul900day-laravel-captcha)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5016.9k1](/packages/simplesamlphp-simplesamlphp-module-oidc)[kinde-oss/kinde-auth-php

Kinde PHP SDK for authentication

2369.5k3](/packages/kinde-oss-kinde-auth-php)[descope/descope-php

Descope SDK for PHP

3814.0k](/packages/descope-descope-php)[njoguamos/laravel-turnstile

A laravel wrapper for https://developers.cloudflare.com/turnstile/

2315.9k2](/packages/njoguamos-laravel-turnstile)

PHPackages © 2026

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