2017 © Pedro Peláez
 

library larasocialplus

image

stanwarri/larasocialplus

  • Monday, April 18, 2016
  • by stanwarri
  • Repository
  • 2 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel 5 SocialPlus

Installation

Add this to your composer.json file, (*1)

Laravel 5.2:

``` bash "stanwarri/larasocialplus": "dev-master", (*2)


### Laravel 5.1: ``` bash "stanwarri/larasocialplus": "1.0.0"

Service Provider

Append this to your list of service providers in config/app.php, (*3)

php 'Stanwarri\SocialPlus\SocialPlusServiceProvider', (*4)

Run the command below, (*5)

$ php artisan vendor:publish --provider="Stanwarri\SocialPlus\SocialPlusServiceProvider"

Social Providers

[TODO - Extract from socialite], (*6)

Add provider configuration in config/services.php, (*7)

"facebook": {
    "client_id": "...",
    "client_secret": "..."
}

Handlers

Handlers are a way SocialPlus delegates performing custom behaviours in your application, (*8)

during pre-authorization (authorize request) and post-authorization (callback request)., (*9)

This is where you may implement your login workflow and whatever., (*10)

Handlers are registered in config/socialplus.php like so, (*11)

<?php

return [
    'authorize_handlers' => [
        'login' => App\Handlers\SocialPlus\LoginHandler::class
    ]
];

Suggestion: Handlers should be placed in app/Handlers/SocialPlus folder, (*12)

Example Handler

namespace App\Handlers\SocialPlus;

use Stanwarri\SocialPlus\AuthorizeHandler;
use Laravel\Socialite\Contracts\User as SocialiteUser;

class LoginHandler implements AuthorizeHandler
{
    public function authorize($provider)
    {
        // Called before any request is made to the provider
    }

    public function callback(SocialiteUser $socialiteUser, $accessToken, $provider)
    {
        // Executed after a successful authorization
    }

    public function exception($exception, $provider)
    {
        // Executed when an exception occurs / authorization fails
    }
}

Once you done registering the handler, you create a link like so;, (*13)

// - route('socialplus.authorize', ['provider' => 'facebook', 'a' => 'login'])

// - Like So:

<a href="{{ route('socialplus.authorize', ['provider' => 'facebook', 'a' => 'login']) }}">Login With Facebook</a>

notice the 'a' parameter? .... That's the value you use to connect handler we just created and, (*14)

its what tells socialplus what handler to use for that specific action., (*15)

Contribute

[WIP] This documentation is a work in progress and would really appreciate contributions. :), (*16)

The Versions