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

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

smallhadroncollider/social-login
================================

A package to make Social Login easier for API-centric PHP applications

0.6.3(10y ago)1721MITPHPPHP &gt;=5.5.0

Since Sep 17Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (9)Used By (0)

Social Login
============

[](#social-login)

[![Version](https://camo.githubusercontent.com/e8b98a6cdd7d79d0a9e99af73828756d2d7e46b254895a22f9f249d442eb8a51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d616c6c686164726f6e636f6c6c696465722f736f6369616c2d6c6f67696e2e706e673f7374796c653d666c6174)](https://packagist.org/packages/smallhadroncollider/social-login) [![Build Status](https://camo.githubusercontent.com/196e2be97b808e2309a1bc0580346ed012e53cecf570fe5cee269fb069a7acea/68747470733a2f2f7472617669732d63692e6f72672f736d616c6c686164726f6e636f6c6c696465722f736f6369616c2d6c6f67696e2e737667)](https://travis-ci.org/smallhadroncollider/social-login)

[Laravel Socialite](https://github.com/laravel/socialite) is great. But it wasn't created with [API-centric](http://code.tutsplus.com/tutorials/creating-an-api-centric-web-application--net-23417) PHP apps in mind: it relies on sessions (which a stateless API will lack) and specific `GET` parameters (which may not be desirable).

The Social Login package is designed to make it easy to add Social Login to apps where you have, for example, an OAuth 2 protected API.

Typical Usage with an OAuth 2 API
---------------------------------

[](#typical-usage-with-an-oauth-2-api)

- **Client**: Generate a session and request the authorisation URLs from the API

```
/*
 * GET https://mysite.com/login
 */

// start a session
session_start();
$sessionID = session_id();

// get the list of supported social login urls
$urls = $http->get("https://api.mysite.com/v1/auth/social/urls", [
    "session_id" => $sessionID,
]);
```

- **API**: Create a new instance of `SocialLogin` using session id

```
/*
 * GET https://api.mysite.com/v1/auth/social/urls
 */

use SmallHadronCollider\SocialLogin\SocialLogin;
use SmallHadronCollider\SocialLogin\Storers\MemcachedStorer;

$config = [
    "facebook" => [
        "client_id" => "1",
        "client_secret" => "secret",
        "redirect_url" => "https://mysite.com/login/social?platform=facebook",
    ],
];

$storer = new MemcachedStorer();

$login = new SocialLogin($config, $storer);
$login->setSessionID($_GET["session_id"]);

return json_encode($login->getAuthUrls());
```

- **Client**: Send user to the third-party authorisation page

```
/*
 * GET https://mysite.com/login
 */
