Microsoft Azure

socialiteproviders/microsoft-azure image

Microsoft Azure stats

Downloads
1.5M
Stars
42
Open Issues
0
Forks
22

View on GitHub →

Microsoft Azure OAuth2 Provider for Laravel Socialite

Microsoft Azure Integration for Laravel

The socialiteproviders/microsoft-azure package extends Laravel's Socialite to allow authentication with Microsoft Azure Active Directory. This package simplifies integrating Azure AD into Laravel applications by leveraging Socialite's streamlined OAuth flows.

Key Features:

  • Simple Configuration: Easily configure the service within Laravel's config/services.php.
  • Event Listener Setup: Utilize Laravel's event system to handle OAuth events.
  • Flexible Usage: Supports standard and advanced scenarios, including handling multiple Azure AD tenants.

Installation Guide:

  1. Add Package:

    composer require socialiteproviders/microsoft-azure
  2. Configuration: Add Azure credentials to your config/services.php:

    'azure' => [
    'client_id' => env('AZURE_CLIENT_ID'),
    'client_secret' => env('AZURE_CLIENT_SECRET'),
    'redirect' => env('AZURE_REDIRECT_URI'),
    'tenant' => env('AZURE_TENANT_ID'),
    'proxy' => env('PROXY') // optionally
    ],
  3. Event Listener: Register the Azure provider event listener in app/Providers/EventServiceProvider:

    protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
    \SocialiteProviders\Azure\AzureExtendSocialite::class.'@handle',
    ],
    ];

Basic Usage:

  • Redirect to Azure for Authentication:

    return Socialite::driver('azure')->redirect();
  • Handle Logout:

    public function logout(Request $request) {
    Auth::guard()->logout();
    $request->session()->flush();
    $azureLogoutUrl = Socialite::driver('azure')->getLogoutUrl(route('login'));
    return redirect($azureLogoutUrl);
    }

Advanced Usage:

For scenarios involving multiple Azure AD tenants, configure and use a custom set of credentials:

function getConfig(): \SocialiteProviders\Manager\Config {
return new \SocialiteProviders\Manager\Config(
env('AD_CLIENT_ID', 'some-client-id'),
env('AD_CLIENT_SECRET'),
url(env('AD_REDIRECT_PATH', '/azuread/callback')),
['tenant' => env('AD_TENANT_ID', 'common')]
);
}
 
Socialite::driver('azure')
->setConfig(getConfig())
->redirect();

Ensure to use the custom configuration when retrieving user details as well:

$socialUser = Socialite::driver('azure')
->setConfig(getConfig())
->user();

Returned User Fields:

  • id
  • name
  • email

This package offers a robust and flexible solution for integrating Microsoft Azure AD with Laravel, providing both simplicity in common use cases and flexibility for more complex scenarios.

SocialiteProviders photo

Socialite Providers for Laravel

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Socialiteproviders Microsoft Azure Related Articles

SQL Server coming to Linux image

SQL Server coming to Linux

Read article
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel