rzb/social-auth is a Laravel package for social authentication boilerplate..
It currently has 0 GitHub stars and 143 downloads on Packagist (latest version v1.0.10).
Install it with composer require rzb/social-auth.
Discover more Laravel packages by rzb
or browse all Laravel packages to compare alternatives.
Last updated
Socialite wrapper that handles all the remaining social authentication boilerplate, exposing endpoints ready for use that enable multiple providers at once for any model(s) you need.
$ composer require rzb/socialauth
$ php artisan migrate
<?php
namespace App\Models\User;
use Rzb\SocialAuth\Contracts\Resourceable as ResourceableContract;
use Rzb\SocialAuth\Contracts\Sociable as SociableContract;
use Rzb\SocialAuth\Traits\Resourceable;
use Rzb\SocialAuth\Traits\Sociable;
// ...
class User extends AuthUser implements SociableContract, ResourceableContract
{
use Resourceable;
use Sociable;
// ...
}
$ php artisan vendor:publish --provider="Rzb\SocialAuth\SocialAuthServiceProvider" --tag="config"
By default, once installed the package automatically exposes 2 stateless endpoints and accepts Google, Facebook and Twitter providers for the User model. These routes expect the same 2 segments.
GET /auth/social/{provider}/{sociable}
POST /auth/social/{provider}/{sociable}
[
'access_token' => 'required|string' // incoming token from provider
]
provider - the provider name. e.g. google, facebook, etc.
sociable - the name of the sociable model as per your config file. e.g.user, customer, etc.
For most projects, you won't have to do anything at all after installation. If however you have different needs, you're free to tweak the configuration to add/remove models and providers, use your own controller or even implement your own DB logic.
You can support authentication for any model you want.
sociables key in the config file, indicating the model class and the providers you want to allow specifically for that model. // config/socialauth.php
'sociables' => [
// default model. You can remove it or tweak it.
'user' => [
'model' => User::class,
'providers' => [
'google',
'facebook',
'twitter',
],
],
// Customer model example
// 'customer' => [
// 'model' => Customer::class,
// 'providers' => [
// 'google',
// 'github',
// ],
// ],
],
// Transforms User profile info from the social account to your sociable model.
use Rzb\SocialAuth\Contracts\Sociable as SociableContract;
use Rzb\SocialAuth\Traits\Sociable;
// Converts your sociable model to its respective JsonResource class.
// Only needed if you're using the package's default controller.
use Rzb\SocialAuth\Contracts\Resourceable as ResourceableContract;
use Rzb\SocialAuth\Traits\Resourceable;
You can apply middlewares and route prefix to the package routes. Or even replace its controller with your own.
// config/socialauth.php
'routes' => [
'controller' => SocialAuthController::class,
'middleware' => null,
'prefix' => 'auth/social',
],
The Sociable trait covers a basic User model with username and password. If your model has a different structure you may want to define your own createFromSocialUser method.
use Laravel\Socialite\Contracts\User as SocialUser;
public static function createFromSocialUser(SocialUser $socialUser): self
{
return self::forceCreate([
// map your model attributes here
'email' => $socialUser->getEmail(),
'name' => $socialUser->getName(),
]);
}