Easily sign-in and poll users and groups in Microsoft Entra
Requires
- php: ^8.3
- dcblogdev/laravel-microsoft-graph: ^4
- illuminate/support: ^11
Requires (Dev)
This package is auto-updated.
Last update: 2025-02-06 12:47:00 UTC
README
Easily sign-in and poll users and groups in Microsoft Entra, built using Laravel Microsoft Graph.
Setup
- Install this library using
Composer
:composer require networkrailbusinesssystems/entra
- Publish the Entra configuration file using
Artisan
:php artisan vendor:publish --provider="NetworkRailBusinessSystems\Entra\EntraServiceProvider" --tag="entra"
- Adjust the
entra.php
configuration file to suit your needs.sync_attributes
will automatically create and update Models to match the details from Entrauser_model
should be the fully qualified class name of the Model used for Laravel authentication
- Implement the
EntraAuthenticatable
interface on your chosen Model - Add the
AuthenticatesWithEntra
trait on your chosen Model for a standard fetch and sync setup, or implement the methods yourself - Add the Entra authentication routes to your
routes/web.php
using the macro:Route::entra(); Route::middleware('MsGraphAuthenticated')->group(function () { // Your authenticated routes here... }
Usage
Users will automatically be redirected to the Microsoft Azure login page whenever they attempt to access an authenticated route as a guest.
The EntraServiceProvider
automatically registers the relevant event listeners for authentication.
You can use the Laravel Microsoft Graph
library as normal.
Manual sign-in and out
You can allow users to manually login by providing link to the login
route.
Users can logout by calling the logout
route.
Entra sign-in response
An example of the response given by the Entra sign-in endpoint is provided for reference below.
Dcblogdev\MsGraph\Events\NewMicrosoft365SignInEvent { +token: [ "info" => [ "@odata.context" => "https://graph.microsoft.com/v1.0/$metadata#users/$entity", "businessPhones" => [ "01234567890", ], "displayName" => "Joe Bloggs", "givenName" => "Joe", "jobTitle" => "Business Systems Developer", "mail" => "Joe.Bloggs@networkrail.co.uk", "mobilePhone" => "01234567890", "officeLocation" => "Some Office", "preferredLanguage" => null, "surname" => "Bloggs", "userPrincipalName" => "JBloggs2@networkrail.co.uk", "id" => "123ab4c5-6789-01de-f2g3-45678hijk9lm", ], "accessToken" => "... A string which is ~2400 characters long ...", "refreshToken" => ".. A string which is ~2400 characters long ...", "expires" => 1234567890, ], +socket: null, }