morrelinko / laravel5-socialplus
Requires
- illuminate/console: 5.1.*
- illuminate/contracts: 5.1.*
- illuminate/session: 5.1.*
- illuminate/support: 5.1.*
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-08-03 16:50:38 UTC
README
Installation
Add this to your composer.json
file
Append this to your list of service providers in config/app.php
'Morrelinko\SocialPlus\SocialPlusServiceProvider'
Run the command below
$ php artisan vendor:publish --provider="Morrelinko\SocialPlus\SocialPlusServiceProvider"
Social Providers
[TODO - Extract from socialite]
Add provider configuration in config/services.php
"facebook": {
"client_id": "...",
"client_secret": "..."
}
Handlers
Handlers are a way SocialPlus delegates performing custom behaviours in your application
during pre-authorization (authorize request) and post-authorization (callback request).
This is where you may implement your login workflow and whatever.
Handlers are registered in config/socialplus.php
like so
<?php
return [
'authorize_handlers' => [
'login' => App\Handlers\SocialPlus\LoginHandler::class
]
];
Suggestion: Handlers should be placed in app/Handlers/SocialPlus
folder
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;
// - 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
its what tells socialplus what handler to use for that specific action.
Contribute
[WIP] This documentation is a work in progress and would really appreciate contributions. :)