PHP code example of edrisaturay / filament-azure-socialite

1. Go to this page and download the library: Download edrisaturay/filament-azure-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/ */

    

edrisaturay / filament-azure-socialite example snippets


'azure' => [
    'client_id' => env('AZURE_CLIENT_ID'),
    'client_secret' => env('AZURE_CLIENT_SECRET'),
    'redirect' => env('AZURE_REDIRECT_URI'), // Optional
    'tenant' => env('AZURE_TENANT_ID', 'common'),
    'proxy' => env('PROXY'), // Optional
],

use EdrisaTuray\FilamentAzureSocialite\FilamentAzureSocialitePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentAzureSocialitePlugin::make()
                ->enabled()
                ->buttonLabel('Login with Microsoft')
                ->hook('after') // or 'before'
                ->allowRegistration(true)
                ->allowedDomains(['company.com']) // Optional
                ->allowedTenants(['tenant-id']) // Optional
        ]);
}

use EdrisaTuray\FilamentAzureSocialite\FilamentAzureSocialitePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentAzureSocialitePlugin::make()
                ->enabled()
                ->buttonLabel('Login with Microsoft')
                ->hook('after')
                ->allowRegistration(true)
        ]);
}

FilamentAzureSocialitePlugin::make()
    ->enabled(true)                    // Enable/disable the plugin
    ->buttonLabel('Login with Microsoft') // Button text
    ->hook('after')                    // 'before' or 'after' the login form
    ->allowRegistration(true)          // Allow creating new users

FilamentAzureSocialitePlugin::make()
    ->allowedDomains(['company.com', 'partner.com']) // Restrict to specific email domains
    ->allowedTenants(['tenant-id-1', 'tenant-id-2']) // Restrict to specific Azure tenants

FilamentAzureSocialitePlugin::make()
    ->resolveUserUsing(function ($azureUser) {
        // Custom logic to find or create user
        return User::firstOrCreate(
            ['email' => $azureUser->getEmail()],
            [
                'name' => $azureUser->getName(),
                'role' => 'user',
            ]
        );
    })

FilamentAzureSocialitePlugin::make()
    ->beforeRedirect(function ($request, $config) {
        // Called before redirecting to Azure
        // You can modify $config here
    })
    ->afterUserResolved(function ($user, $azureUser) {
        // Called after user is resolved/created
        // Useful for syncing additional data
    })

// Admin Panel
AdminPanelProvider::class => [
    FilamentAzureSocialitePlugin::make()
        ->enabled()
        ->allowedDomains(['admin.company.com'])
],

// User Panel
UserPanelProvider::class => [
    FilamentAzureSocialitePlugin::make()
        ->enabled()
        ->allowedDomains(['company.com'])
        ->allowRegistration(true)
],

Schema::table('users', function (Blueprint $table) {
    $table->string('azure_id')->nullable()->unique();
});
bash
php artisan filament-azure-socialite:install
bash
php artisan filament-azure-socialite:doctor
bash
php artisan filament-azure-socialite:install