GithubHelp home page GithubHelp logo

yob-yob / filament-socialite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dutchcodingcompany/filament-socialite

0.0 0.0 0.0 105 KB

Add OAuth login through Laravel Socialite to Filament.

License: MIT License

PHP 95.77% Blade 4.23%

filament-socialite's Introduction

Social login for Filament through Laravel Socialite

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Add OAuth login through Laravel Socialite to Filament.

Installation

You can install the package via composer:

composer require dutchcodingcompany/filament-socialite

You can publish and run the migrations with:

php artisan vendor:publish --tag="filament-socialite-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="filament-socialite-config"

See the contents of the config file here.

Providers

You should setup the providers with Socialite and/or Socialite Providers and add them to the providers array in the filament-socialite.php config.

Icons

You can specify a Blade Icon. You can add Font Awesome brand icons made available through Blade Font Awesome by running:

composer require owenvoke/blade-fontawesome

Registration flow

This package supports account creation for users. However, to support this flow it is important that the password attribute on your User model is nullable. For example, by adding the following to your users table migration. Or you could opt for customizing the user creation, see below.

$table->string('password')->nullable();

Domain Allowlist

This package supports the option to limit the users that can login with the OAuth login to users of a certain domain. This can be used to setup SSO for internal use.

Customizing view

Optionally, you can publish the views using

php artisan vendor:publish --tag="filament-socialite-views"

Changing how a (socialite) user is created or retrieved

In your AppServiceProvider.php, add in the boot method

use Laravel\Socialite\Contracts\User as SocialiteUserContract;
use DutchCodingCompany\FilamentSocialite\Facades\FilamentSocialite as FilamentSocialiteFacade;
use DutchCodingCompany\FilamentSocialite\FilamentSocialite;

// Default
FilamentSocialiteFacade::setCreateUserCallback(fn (SocialiteUserContract $oauthUser, FilamentSocialite $socialite) => $socialite->getUserModelClass()::create([
    'name' => $oauthUser->getName(),
    'email' => $oauthUser->getEmail(),
]));

One can set a callback to customize the following actions:

  • Create the filament user: FilamentSocialite::setCreateUserCallback()
  • Create the socialite user: FilamentSocialite::setCreateSocialiteUserCallback()
  • Resolve the regular user: FilamentSocialite::setUserResolver()

See FilamentSocialite.php.

Usage

Add the buttons component to your login page, just above the </form> closing tag:

    <x-filament-socialite::buttons />
</form>

You can publish the login page for vanilla Filament by running:

php artisan vendor:publish --tag="filament-views"

Which produces a login page at resources/views/vendor/filament/login.blade.php.

Filament Fortify

This component can also be added while using the Fortify plugin plugin.

## in Service Provider file
public function boot()
{
    //...
    
    Filament::registerRenderHook(
        'filament-fortify.login.end',
        fn (): string => Blade::render('@livewire(\'filament-socialite.buttons\')'),
    );
}

Filament Breezy

This component can also be added while using the Breezy plugin plugin.

You can publish the login page for Filament Breezy by running:

php artisan vendor:publish --tag="filament-breezy-views"

Which produces a login page at resources/views/vendor/filament-breezy/login.blade.php.

Events

There are a few events dispatched during the authentication process:

  • Login: When a user successfully logs in
  • Registered: When a user is successfully registered and logged in (when enabled in config)
  • UserNotAllowed: When a user tries to login with an email which domain is not on the allowlist
  • RegistrationNotEnabled: When a user tries to login with an unknown account and registration is not enabled
  • InvalidState: When trying to retrieve the oauth (socialite) user, an invalid state was encountered

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-socialite's People

Contributors

marcoboers avatar dododedodonl avatar dependabot[bot] avatar github-actions[bot] avatar caendesilva avatar oyepez003 avatar andresilvagomez avatar shaqaruden avatar wivaku avatar wychoong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.