2017 © Pedro Peláez
 

library laravel5-socialplus

image

morrelinko/laravel5-socialplus

  • Friday, July 31, 2015
  • by morrelinko
  • Repository
  • 1 Watchers
  • 2 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel 5 SocialPlus

Installation

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

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

'Morrelinko\SocialPlus\SocialPlusServiceProvider'

Run the command below, (*3)

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

Social Providers

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

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

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

Handlers

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

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

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

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

<?php

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

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

Example Handler

namespace App\Handlers\SocialPlus;

use Morrelinko\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;, (*11)

// - 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, (*12)

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

Contribute

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

The Versions