This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Colored ScienceProvider for Laravel Socialite

dev-master 2019-07-01 07:35 UTC

This package is auto-updated.

Last update: 2021-09-29 02:22:41 UTC


This is an extended provider of Laravel Socialite for ColoredScience authentication using the SocialiteProviders Manager.


composer require laravel/socialite
composer require coloredscience/laravel-auth

Create your app on Colored User to obtain API keys.


  • Add a configurable service in config\services.php for Laravel Socialite connection:

        'coloredsci' => [
            'client_id' => env('CS_CLIENT_ID'),
            'client_secret' => env('CS_CLIENT_SECRET'),
            'redirect' => env('APP_URL').env('CS_REDIRECT'),
  • Remove Laravel\Socialite\SocialiteServiceProvider from your providers[] array in config\app.php if you have added it already.

  • Register this provider instead

        'providers' => [
            // a whole bunch of providers
            // remove 'Laravel\Socialite\SocialiteServiceProvider',
            \SocialiteProviders\Manager\ServiceProvider::class, // add
  • Add SocialiteProviders\Manager\SocialiteWasCalled event to your listen[] array in app/Providers/EventServiceProvider

  • Add the Colored Science listener to the SocialiteProviders\Manager\SocialiteWasCalled[] that you just created

        protected $listen = [
            \SocialiteProviders\Manager\SocialiteWasCalled::class => [
  • Create your Authentication Controller to manage the authentication flow

        php artisan make:controller Auth\\CSAuthController
  • Register your Auth Routes

    Route::get('/login', 'Auth\CSAuthController@login' )->name( 'login' );
    Route::get('/callback', 'Auth\CSAuthController@handleCallback' )->name( 'callback' );
    Route::get('/logout', 'Auth\CSAuthController@logout' )->name( 'logout' )->middleware('auth');
  • Create a login and logout function to handle the CS Socialite authentication and logout, more usage options are available via Laravel Socialite

        public function login()
            return Socialite::with('coloredsci')->redirect();
        public function logout()
            return  \Redirect::intended('/');
  • Create a callback function to handle the redirect callback, more usage options are available via Laravel Socialite

        public function handleCallback()
            $user = Socialite::driver('coloredsci')->user();
            $authUser = $this->updateOrCreateUser($user);
            Auth::login($authUser, true);
            return redirect('/home');
        public function updateOrCreateUser($user) {
            return $authUser  = User::updateOrCreate(
                ['email' => $user->email],
                    'fname' => $user->fname,
                    'lname' => $user->lname,
                    'nickname' => $user->nickname,
                    'avatar' => $user->avatar,
                    'phone' => $user->phone,
                    'email_verified_at' => $user->email_verified_at,