DutchCodingCompany / filament-socialite

Add OAuth login through Laravel Socialite to Filament.
MIT License
153 stars 38 forks source link

Authorization Callback #100

Closed petecoop closed 3 months ago

petecoop commented 3 months ago

This is something I needed for an integration I'm working on, where only users with an admin user level should be able to login to the system but this could be customised to reject a user for any reason.

Usage:

FilamentSocialitePlugin::make()
    // ...
    ->authorizeUserUsing(function (User $oauthUser) {
        // Logic to authorize a user e.g.
        return $oauthUser->getRaw()['user_level'] === 'admin';
    });
bramr94 commented 3 months ago

Thank you for your contribution, this is a nice feature to have! I've combined it with the existing isUserAllowed function and added some new tests.

petecoop commented 3 months ago

Wow nice you've really tidied up the feature I added :)

The only downside I see is that no matter what check you put in you will get the error message of "Your email is not part of a domain that is allowed." although that isn't the reason - it's down to the custom closure. This is one reason I separated it out into it's own method but I was wondering if there could be a way to pass a validation message that could be displayed on failure.

bramr94 commented 3 months ago

@petecoop You should be able to publish the translation files and change it. The only reason I reversed the translation was because it would introduce a breaking change.

We will address this when we do a new major release.

petecoop commented 3 months ago

@bramr94 Yeah sorry what I meant is that there is no way to provide a different message depending on if not in the domain list or have failed the custom check - either one will provide the same message