PHPackages                             ravindrasingh0406/social-login - 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. ravindrasingh0406/social-login

ActiveLibrary

ravindrasingh0406/social-login
==============================

Framework-agnostic social login package for PHP with multiple providers (Google, GitHub)

v1.0.2(6mo ago)01MITPHPPHP &gt;=8.0

Since Nov 6Pushed 6mo agoCompare

[ Source](https://github.com/codeFreak2020/social-login)[ Packagist](https://packagist.org/packages/ravindrasingh0406/social-login)[ Docs](https://github.com/codeFreak2020/social-login)[ RSS](/packages/ravindrasingh0406-social-login/feed)WikiDiscussions feature/social-login Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Social Login (Framework-agnostic)
=================================

[](#social-login-framework-agnostic)

A tiny, framework-agnostic PHP library to handle OAuth2 social login with multiple providers. It uses `league/oauth2-client` under the hood and ships with **6 built-in providers** plus full extensibility for any OAuth2 service.

✨ Features
----------

[](#-features)

- 🔐 **6 Built-in Providers**: Google, GitHub, Facebook, LinkedIn, Microsoft, Twitter/X
- 🏢 **Custom OAuth2 Support**: Use your own OAuth2 server as a provider
- 🔌 **Fully Extensible**: Add any OAuth2 provider in minutes
- 🚀 **Framework-agnostic**: Works with any PHP application
- 💎 **Laravel Support**: Auto-discovery, Facade, publishable config
- 🧪 **Well-tested**: PHPUnit test suite included
- 📦 **Zero Config**: Sensible defaults, customize as needed

Install
-------

[](#install)

Require via Composer:

```
composer require ravindrasingh0406/social-login
```

> Note: This package depends on `league/oauth2-client` and `guzzlehttp/guzzle`.

Laravel usage
-------------

[](#laravel-usage)

This package supports Laravel Package Auto-Discovery.

1. Install

```
composer require ravindrasingh0406/social-login
```

2. Publish config (optional)

```
php artisan vendor:publish --tag=social-login-config
```

This creates `config/social-login.php` so you can set credentials or use env vars:

```
SOCIAL_GOOGLE_CLIENT_ID=...
SOCIAL_GOOGLE_CLIENT_SECRET=...
SOCIAL_GOOGLE_REDIRECT_URI=https://your-app.test/auth/callback?provider=google

SOCIAL_GITHUB_CLIENT_ID=...
SOCIAL_GITHUB_CLIENT_SECRET=...
SOCIAL_GITHUB_REDIRECT_URI=https://your-app.test/auth/callback?provider=github

```

3. Use via Facade or DI

```
use SocialLogin\Laravel\Facades\SocialLogin; // Facade
// or type-hint SocialLogin\Manager $social in constructors

// Step 1: redirect
$authUrl = SocialLogin::getAuthorizationUrl();
session(['oauth2state' => SocialLogin::getState()]);
return redirect()->away($authUrl);

// Step 2: callback
abort_unless(request('state') === session('oauth2state'), 400, 'Invalid state');
$token = SocialLogin::fetchAccessToken(request('code'));
$user = SocialLogin::fetchUser($token['access_token']);
```

To select a specific provider, resolve the `Manager` and call `driver('google'|'github')`:

```
use SocialLogin\Manager;

public function redirectGoogle(Manager $social)
{
    $driver = $social->driver('google');
    return redirect()->away($driver->getAuthorizationUrl());
}
```

Quick start (generic PHP)
-------------------------

[](#quick-start-generic-php)

```
use SocialLogin\Manager;

$config = [
    'providers' => [
        'google' => [
            'client_id' => 'GOOGLE_CLIENT_ID',
            'client_secret' => 'GOOGLE_CLIENT_SECRET',
            'redirect_uri' => 'https://your-app.test/callback?provider=google',
            // Optional: 'scopes' => ['openid','email','profile'],
        ],
        'github' => [
            'client_id' => 'GITHUB_CLIENT_ID',
            'client_secret' => 'GITHUB_CLIENT_SECRET',
            'redirect_uri' => 'https://your-app.test/callback?provider=github',
            // Optional: 'scopes' => ['read:user','user:email'],
        ],
    ],
];

$manager = new Manager($config);
$driver = $manager->driver('google');

// 1) Redirect user to provider
$authUrl = $driver->getAuthorizationUrl();
$state = $driver->getState(); // persist this in session to validate later
header('Location: '.$authUrl);
exit;

// 2) In callback handler
$token = $driver->fetchAccessToken($_GET['code']);
$user = $driver->fetchUser($token['access_token']);
```

Demo app
--------

[](#demo-app)

A tiny demo is available in `examples/public`:

- Copy `examples/public/config.sample.php` to `examples/public/config.php` and fill credentials
- Serve the folder, e.g.:

```
php -S localhost:8000 -t examples/public
```

Then open  in your browser.

Supported Providers
-------------------

[](#supported-providers)

ProviderNameDefault ScopesGoogle`google``openid`, `email`, `profile`GitHub`github``read:user`, `user:email`Facebook`facebook``email`, `public_profile`LinkedIn`linkedin``openid`, `profile`, `email`Microsoft`microsoft``openid`, `profile`, `email`, `User.Read`Twitter/X`twitter``tweet.read`, `users.read`**Want to add more?** See [EXTENDING.md](EXTENDING.md) for a complete guide on adding any OAuth2 provider.

### Quick Example: Facebook

[](#quick-example-facebook)

```
$config = [
    'providers' => [
        'facebook' => [
            'client_id' => 'YOUR_FACEBOOK_APP_ID',
            'client_secret' => 'YOUR_FACEBOOK_SECRET',
            'redirect_uri' => 'https://your-app.com/auth/facebook/callback',
        ],
    ],
];

$manager = new Manager($config);
$driver = $manager->driver('facebook');
$authUrl = $driver->getAuthorizationUrl();
```

Extensibility
-------------

[](#extensibility)

### Adding Custom Providers

[](#adding-custom-providers)

This package is designed to be **fully extensible**. Add any OAuth2 provider in 3 ways:

#### Method 1: Register globally (recommended)

[](#method-1-register-globally-recommended)

```
use SocialLogin\Manager;
use App\OAuth\DiscordProvider;

Manager::extend('discord', DiscordProvider::class);

$driver = $manager->driver('discord');
```

#### Method 2: Specify in config

[](#method-2-specify-in-config)

```
$config = [
    'providers' => [
        'discord' => [
            'driver' => \App\OAuth\DiscordProvider::class,
            'client_id' => '...',
            'client_secret' => '...',
            'redirect_uri' => '...',
        ],
    ],
];
```

#### Method 3: Create a provider class

[](#method-3-create-a-provider-class)

```
use SocialLogin\Providers\AbstractOAuth2Provider;
use SocialLogin\DTO\User;

class DiscordProvider extends AbstractOAuth2Provider
{
    protected function authorizeUrl(): string
    {
        return 'https://discord.com/api/oauth2/authorize';
    }

    protected function tokenUrl(): string
    {
        return 'https://discord.com/api/oauth2/token';
    }

    protected function defaultScopes(): array
    {
        return ['identify', 'email'];
    }

    protected function doFetchUser(string $accessToken): User
    {
        // Fetch and map user data
        $resp = $this->http->get('https://discord.com/api/users/@me', [
            'headers' => ['Authorization' => 'Bearer ' . $accessToken],
        ]);
        $data = json_decode((string) $resp->getBody(), true);

        return new User(
            id: $data['id'],
            name: $data['username'],
            email: $data['email'] ?? null,
            avatar: "https://cdn.discordapp.com/avatars/{$data['id']}/{$data['avatar']}.png",
            raw: $data,
            provider: 'discord'
        );
    }
}
```

**📖 Full Guide**: See [EXTENDING.md](EXTENDING.md) for complete documentation, real-world examples (Slack, Apple, Discord), and testing strategies.

Using Your Own OAuth2 Server
----------------------------

[](#using-your-own-oauth2-server)

You can use this package with **your own custom OAuth2 authentication server** - perfect for enterprise SSO, multi-tenant applications, or custom authentication services.

### Quick Example

[](#quick-example)

```
use SocialLogin\Providers\GenericOAuth2Provider;

$config = [
    'providers' => [
        'my-auth-service' => [
            'driver' => GenericOAuth2Provider::class,
            'client_id' => 'your_client_id',
            'client_secret' => 'your_client_secret',
            'redirect_uri' => 'https://your-app.com/auth/callback',

            // Your OAuth2 server endpoints
            'authorize_url' => 'https://auth.yourcompany.com/oauth/authorize',
            'token_url' => 'https://auth.yourcompany.com/oauth/token',
            'userinfo_url' => 'https://auth.yourcompany.com/api/user',

            'scopes' => ['openid', 'profile', 'email'],
        ],
    ],
];

$manager = new Manager($config);
$driver = $manager->driver('my-auth-service');
```

### Works With Popular OAuth2 Servers

[](#works-with-popular-oauth2-servers)

- **Laravel Passport** - Full OAuth2 server for Laravel apps
- **Keycloak** - Open-source identity and access management
- **Auth0** - Authentication and authorization platform
- **Your Custom Server** - Any OAuth2-compliant server

**📖 Complete Guide**: See [CUSTOM\_OAUTH2.md](CUSTOM_OAUTH2.md) for:

- Building your own OAuth2 server
- Complete configuration options
- Field mapping and customization
- Laravel Passport, Keycloak, and Auth0 examples
- Security best practices

More Providers
--------------

[](#more-providers)

More can be added by implementing `SocialLogin\\Contracts\\ProviderDriver` and extending `Providers\\AbstractOAuth2Provider`.

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance68

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

3

Last Release

187d ago

### Community

Maintainers

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

---

Top Contributors

[![ravindraSingh1994](https://avatars.githubusercontent.com/u/223264085?v=4)](https://github.com/ravindraSingh1994 "ravindraSingh1994 (13 commits)")

---

Tags

laravelgoogleoauth2githubSocial Login

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ravindrasingh0406-social-login/health.svg)

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

###  Alternatives

[hwi/oauth-bundle

Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony.

2.4k21.5M69](/packages/hwi-oauth-bundle)[and/oauth

Simple and amazing OAuth library with many providers. Just try it out!

4645.2k2](/packages/and-oauth)

PHPackages © 2026

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