PHPackages                             networkrailbusinesssystems/entra - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. networkrailbusinesssystems/entra

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

networkrailbusinesssystems/entra
================================

Easily sign-in and poll users and groups in Microsoft Entra

1.4.0(2mo ago)070—0%[2 PRs](https://github.com/Network-Rail-Business-Systems/entra/pulls)1MITPHPPHP ^8.3

Since Feb 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Network-Rail-Business-Systems/entra)[ Packagist](https://packagist.org/packages/networkrailbusinesssystems/entra)[ RSS](/packages/networkrailbusinesssystems-entra/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (9)Versions (10)Used By (1)

Entra
=====

[](#entra)

[![Composer status](.github/composer.svg)](.github/composer.svg)[![Coverage status](.github/coverage.svg)](.github/coverage.svg)[![Laravel version](.github/laravel.svg)](.github/laravel.svg)[![PHP version](.github/php.svg)](.github/php.svg)[![Tests status](.github/tests.svg)](.github/tests.svg)

Easily sign-in and poll users and groups in Microsoft Entra, built using [Laravel Microsoft Graph](https://github.com/dcblogdev/laravel-microsoft-graph).

Setup
-----

[](#setup)

1. Install this library using `Composer`: ```
    composer require networkrailbusinesssystems/entra
    ```
2. Publish the Entra configuration file using `Artisan`: ```
    php artisan vendor:publish --tag="entra"
    ```
3. Publish the MsGraph configuration file ```
    php artisan vendor:publish --provider="Dcblogdev\MsGraph\MsGraphServiceProvider" --tag="config"
    ```

    - You generally only need to set the `scopes` property
    - More information is available in the [Laravel Microsoft Graph](https://github.com/dcblogdev/laravel-microsoft-graph) documentation
4. Publish the MsGraph migration file ```
    php artisan vendor:publish --provider="Dcblogdev\MsGraph\MsGraphServiceProvider" --tag="migrations"
    ```

    - Consider adding a foreign key to the `user_id` column for greater efficiency
5. Adjust the `entra.php` configuration file to suit your needs
6. Setup your authenticatable User model
    - 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
7. Add the Entra authentication routes to your `routes/web.php` using the macro: ```
    Route::entra();

    Route::middleware('MsGraphAuthenticated')->group(function () {
        // Your authenticated routes here...
    }
    ```

Configuration
-------------

[](#configuration)

### create\_users

[](#create_users)

Whether to allow Users without an account in the system already to sign-in.

When set to `true`, Entra will automatically create a new User record for anyone who successfully signs in.

When set to `false`, Users must be manually added before they can sign-in, even with a valid SSO session.

### messages

[](#messages)

Customise any of the error messages thrown by Entra.

KeyUsageexisting\_onlyShown when a new User attempts to log into a system with `create_users` set to `false`### sync\_attributes

[](#sync_attributes)

Any attributes set here will automatically be filled when signing in, keeping the User up to date with any changes in Entra.

The array should contain a key-value pair in `entra => laravel` format.

```
'sync_attributes' => [
    'mail' => 'email',
],
```

### user\_model

[](#user_model)

The fully qualified class name of the Model used for Laravel authentication.

```
use App/Models/User;

'user_model' => User::class,
```

### emulator

[](#emulator)

These attributes controls the Entra emulator, and the mock data available to it.

See the "Emulator" section further on for more information.

Signing in and out
------------------

[](#signing-in-and-out)

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.

### Automatic

[](#automatic)

If you wrap all of your system's endpoints in the `MsGraphAuthenticated` middleware, Users will be automatically kicked to the Entra login page.

Should they become signed out for whatever reason, they will be kicked to the Entra login screen.

This may or may not be desirable based on how much of the system should be available to non-users.

### Manual sign-in and out

[](#manual-sign-in-and-out)

You can allow users to manually login by providing a link to the `login` route, which will take them to the Entra login page.

Users can logout by calling the `logout` route, which will take them to the Entra logout page.

Querying Entra
--------------

[](#querying-entra)

You can use the `Laravel Microsoft Graph` library as normal.

Entra queries on routes outside of the `MsGraphAuthenticated` middleware must connect to Entra first, otherwise the request will hit a 302 redirect and fail.

### Service Accounts

[](#service-accounts)

Calling `MsGraph` will access Entra using the currently signed-in user's credentials.

Calling `MsGraphAdmin` will access Entra as the application, without a signed-in user.

`MsGraphAdmin` should be used for any calls to Entra which are performed in the background, such as queues, jobs, and commands.

Any calls using the models provided by this library will automatically fall back to the `MsGraphAdmin` account if there is no signed-in user.

### MsGraph

[](#msgraph)

A drop-in alias for the `MsGraph` facade has been provided which adds docblocks for IDE support.

### MsGraphAdmin

[](#msgraphadmin)

A drop-in alias for the `MsGraphAdmin` facade has been provided which adds docblocks for IDE support.

### EntraGroup

[](#entragroup)

#### Get

[](#get)

Search for and return a specific group.

ParameterTypeDefaultUsage$termstringA unique string to find the group by$fieldstringmailWhich field to look for the `$term` in$select?array\[\]Which fields to return:returns?arrayThe group as an array, or null#### List

[](#list)

Search for groups which start with a term.

ParameterTypeDefaultUsage$termstringA unique string to find the group by$fieldstringmailWhich field to look for the `$term` in$limitint10How many results to show$select?array\[\]Which fields to return:returnsarrayAn array of groups### EntraGroupMembers

[](#entragroupmembers)

#### Get

[](#get-1)

Retrieve a list of users for a group by the group's ID.

Entra will be polled until all of the group's users have been loaded.

ParameterTypeDefaultUsage$termstringA unique string to find the group by$fieldstringmailWhich field to look for the `$term` in$select?array\['mail'\]Which fields to return:returns?arrayThe group's members as an array, or null### EntraUser

[](#entrauser)

#### Get

[](#get-2)

Search for and return a specific user.

ParameterTypeDefaultUsage$termstringA unique string to find the user by$fieldstringmailWhich field to look for the `$term` in$select?arrayconfig(entra.sync\_attributes)Which fields to return:returns?arrayThe user as an array, or null#### List

[](#list-1)

Search for users which start with a term.

ParameterTypeDefaultUsage$termstringA unique string to find the user by$fieldstringmailWhich field to look for the `$term` in$limitint10How many results to show$select?arrayconfig(entra.sync\_attributes)Which fields to return:returnsarrayAn array of users#### Import

[](#import)

Search for and import a specific user to the database.

If the user already exists they will be updated.

ParameterTypeDefaultUsage$termstringA unique string to find the user by$fieldstringmailWhich field to look for the `$term` in$select?arrayconfig(entra.sync\_attributes)Which fields to return:returns?EntraAuthenticatableThe user model, or nullCommands
--------

[](#commands)

The following Artisan commands are available for use:

CommandParametersUsageentra:import-user$term, $entraField = 'mail'Import a single User by the given termentra:refresh-users$laravelField = 'email', $entraField = 'mail'Re-import all Users in the system by a given fieldRules
-----

[](#rules)

### UserExistsInEntra

[](#userexistsinentra)

Ensure that the given User exists in Entra.

```
// Request data
[
    'email' => 'joe.bloggs@networkrail.co.uk',
];

// FormRequest rules()
'email' => [
    new UserExistsInEntra('mail'),
];
```

You may provide the field to match the value to as the first parameter of the Rule.

Emulator
--------

[](#emulator-1)

It is unlikely that your unit tests will ever be connected to a live Entra instance.

You can mock `MsGraph` for specific calls, however you may prefer to re-use a defined list of results.

The emulator only works with the models provided by this library.

Setting `entra.emulator.enabled = true` in your config will enable the emulator.

You may also use the `AssertsEntra` trait on your base `TestCase` class to make the `useEntraEmulator()` method available in your tests.

Emulation does not support signing in or out.

### EntraGroup and EntraGroupMembers

[](#entragroup-and-entragroupmembers)

Defining a list of `groups` on the `entra.emulator.groups` key will allow you to create a custom list of groups with members which you can re-use.

Performing an `EntraGroup::get` will return a matching group from the list.

Performing an `EntraGroup::list` will return a matching set of results from the list.

Performing an `EntraGroupMembers::get` will return a matching group's members from the list.

### EntraUser

[](#entrauser-1)

Defining a list of `users` on the `entra.emulator.users` key will allow you to create a custom list of users which you can re-use.

Performing an `EntraUser::get` or `EntraUser::import` will return a matching user from the list.

Performing an `EntraUser::list` will return a matching set of results from the list.

### Sample Entra responses

[](#sample-entra-responses)

Sample responses are provided on the relevant EntraModel.

Roadmap
-------

[](#roadmap)

- Add 302 handler to MsGraph facade

Help and support
----------------

[](#help-and-support)

You are welcome to raise any issues or questions on GitHub.

If you wish to contribute to this library, raise an issue before submitting a forked pull request.

Licence
-------

[](#licence)

Published under the MIT licence.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance95

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

7

Last Release

61d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17785811?v=4)[Anthony Edmonds](/maintainers/AnthonyEdmonds)[@AnthonyEdmonds](https://github.com/AnthonyEdmonds)

---

Top Contributors

[![AnthonyEdmonds](https://avatars.githubusercontent.com/u/17785811?v=4)](https://github.com/AnthonyEdmonds "AnthonyEdmonds (59 commits)")

---

Tags

laravelauthmicrosoftgraphEntraAuthenticatable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/networkrailbusinesssystems-entra/health.svg)

```
[![Health](https://phpackages.com/badges/networkrailbusinesssystems-entra/health.svg)](https://phpackages.com/packages/networkrailbusinesssystems-entra)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M344](/packages/tymon-jwt-auth)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M52](/packages/php-open-source-saver-jwt-auth)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)[jurager/teams

Laravel package to manage team functionality and operate with user permissions.

22817.3k](/packages/jurager-teams)[codebot/entrust

This package provides a flexible way to add Role-based Permissions to Laravel

1596.6k](/packages/codebot-entrust)[setiawanhu/sanctum-auth

Laravel package for generating user authentication feature using Laravel Sanctum

132.8k](/packages/setiawanhu-sanctum-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
