PHP code example of dutchcodingcompany / filament-socialite
1. Go to this page and download the library: Download dutchcodingcompany/filament-socialite library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dutchcodingcompany / filament-socialite example snippets
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
use DutchCodingCompany\FilamentSocialite\Provider;
use Filament\Support\Colors;
use Laravel\Socialite\Contracts\User as SocialiteUserContract;
use Illuminate\Contracts\Auth\Authenticatable;
// ...
->plugin(
FilamentSocialitePlugin::make()
// ( ->stateless(false)
->scopes(['...'])
->with(['...']),
])
// (optional) Override the panel slug to be used in the oauth routes. Defaults to the panel ID.
->slug('admin')
// (optional) Enable/disable registration of new (socialite-) users.
->registration(true)
// (optional) Enable/disable registration of new (socialite-) users using a callback.
// In this example, a login flow can only continue if there exists a user (Authenticatable) already.
->registration(fn (string $provider, SocialiteUserContract $oauthUser, ?Authenticatable $user) => (bool) $user)
// (optional) Change the associated model class.
->userModelClass(\App\Models\User::class)
// (optional) Change the associated socialite class (see below).
->socialiteUserModelClass(\App\Models\SocialiteUser::class)
);
namespace App\Models;
use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract;
use Illuminate\Contracts\Auth\Authenticatable;
use Laravel\Socialite\Contracts\User as SocialiteUserContract;
class SocialiteUser implements FilamentSocialiteUserContract
{
public function getUser(): Authenticatable
{
//
}
public static function findForProvider(string $provider, SocialiteUserContract $oauthUser): ?self
{
//
}
public static function createForProvider(
string $provider,
SocialiteUserContract $oauthUser,
Authenticatable $user
): self {
//
}
}
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
use Laravel\Socialite\Contracts\User as SocialiteUserContract;
->plugin(
FilamentSocialitePlugin::make()
// ...
->authorizeUserUsing(function (FilamentSocialitePlugin $plugin, SocialiteUserContract $oauthUser) {
// Logic to authorize the user.
return FilamentSocialitePlugin::checkDomainAllowList($plugin, $oauthUser);
})
// ...
);
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract;
use DutchCodingCompany\FilamentSocialite\Models\SocialiteUser;
FilamentSocialitePlugin::make()
->redirectAfterLoginUsing(function (string $provider, FilamentSocialiteUserContract $socialiteUser, FilamentSocialitePlugin $plugin) {
// Change the redirect behaviour here.
});
## in Service Provider file
public function boot()
{
//...
Filament::registerRenderHook(
'filament-fortify.login.end',
fn (): string => Blade::render('<x-filament-socialite::buttons />'),
);
}
use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin;
use DutchCodingCompany\FilamentSocialite\Provider;
FilamentSocialitePlugin::make()
->providers([
Provider::make('github')
->label('Github')
->icon('fab-github')
->scopes([
// Add scopes here.
'read:user',
'public_repo',
]),
]),