crudadmin/socialite connects Laravel Socialite with CrudAdmin. After a social login it finds the user by e-mail or provider id, or registers a new one. Then it fills in the e-mail, name, avatar and provider columns, and either signs the user in or returns an API token.

Requirements

Version 2.x supports CrudAdmin 6, version 1.x supports CrudAdmin 3 to 5. It installs laravel/socialite, socialiteproviders/manager and google/apiclient.

Installation

The config is published to config/admin_socialite.php. The package has no migrations. The columns come from the fields of your user model.
With CrudAdmin 6, also install laravel/helpers. The package still calls the global array_wrap() and str_random() helpers, which CrudAdmin 6 no longer installs.

Configuration

config/admin_socialite.php
With a list of tables, users are looked up in every model. New users are registered in the first one.

Providers

Install and register the SocialiteProviders package of the providers which are not in Laravel Socialite:
app/Providers/EventServiceProvider.php

Credentials

The package adds the services config of Google, Facebook, Apple, PayPal and Instagram. The redirect url is {SOCIALITE_APP_URL}/socialite/{driver}/callback, SOCIALITE_APP_URL defaults to APP_URL.
  • A provider defined in your config/services.php replaces the whole block of the package.
  • With APPLE_PRIVATE_KEY, the package generates the client secret of Apple for every callback, so APPLE_CLIENT_SECRET can stay empty.
  • PAYPAL_MODE=sandbox switches the paypal driver to the sandbox.

User model

The package writes into these fields when they exist in the user model:
app/Models/User.php
  • When username is required and the provider returns no name, the package calls generateUsername() of the model when it exists.
  • Stateless flows create a token with createToken(). Use HasApiTokens of Sanctum in the model.
An existing user with the same e-mail is signed in without confirmation, and the provider id is stored in his account. Enable only providers which verify e-mail addresses, or reject unverified ones in the DRIVER_MIDDLEWARE hook.