PHPackages                             petrsimunek/laravel-azure-middleware - 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. petrsimunek/laravel-azure-middleware

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

petrsimunek/laravel-azure-middleware
====================================

Azure Middleware Auth

v1.0.2(1y ago)015MITPHPPHP &gt;=5.6.4

Since May 29Pushed 1y agoCompare

[ Source](https://github.com/petrsimunek/laravel-azure-middleware)[ Packagist](https://packagist.org/packages/petrsimunek/laravel-azure-middleware)[ RSS](/packages/petrsimunek-laravel-azure-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

Laravel Azure Middleware
========================

[](#laravel-azure-middleware)

Provides Azure Authentication Middleware for a Laravel App. If you like this, checkout [Laravel Saml Middleware](https://github.com/rootinc/laravel-saml2-middleware)

Normal Installation
-------------------

[](#normal-installation)

1. `composer require petrsimunek/laravel-azure-middleware`
2. run `php artisan vendor:publish --provider="petrsimunek\LaravelAzureMiddleware\AzureServiceProvider"` to install config file to `config/azure.php`
3. In our routes folder (most likely `web.php`), add

```
Route::get('/login/azure', '\petrsimunek\LaravelAzureMiddleware\Azure@azure')
    ->name('azure.login');
Route::get('/login/azurecallback', '\petrsimunek\LaravelAzureMiddleware\Azure@azurecallback')
    ->name('azure.callback');
```

> NOTE: Only need the route names if configuring `redirect_uri` in the portal.

4. In our `App\Http\Kernel.php` add `'azure' => \petrsimunek\LaravelAzureMiddleware\Azure::class,` most likely to the `$routeMiddleware` array.
5. In our `.env` add `AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET and AZURE_RESOURCE`. We can get these values/read more here:  (Hint: AZURE\_RESOURCE should be )
6. As of 0.8.0, we added `AZURE_SCOPE`, which are permissions to be used for the request. We can read more about these here:
7. We also added an optional `AZURE_DOMAIN_HINT` that can be used to help users know which email address they should login with. More info here:
8. Within our app on  point `reply url` to the `/login/azurecallback` route with the full url (ex: ).
9. Add the `azure` middleware to your route groups on any routes that needs protected by auth and enjoy 🎉
10. If you need custom callbacks, see [Extended Installation](#extended-installation).

> NOTE: You may need to add premissions for (legacy) Azure Active Directory Graph As of 0.8.0, we are using v2 of Azure's login API, which allows us to pass scopes, or permissions we'd like to use.

Routing
-------

[](#routing)

`Route::get('/login/azure', '\petrsimunek\LaravelAzureMiddleware\Azure@azure')->name('azure.login');` First parameter can be wherever you want to route the azure login. Change as you would like.

`Route::get('/login/azurecallback', '\petrsimunek\LaravelAzureMiddleware\Azure@azurecallback')->name('azure.callback');` First parameter can be whatever you want to route after your callback. Change as you would like.

`Route::get('/logout/azure', '\petrsimunek\LaravelAzureMiddleware\Azure@azurelogout')->name('azure.logout);` First parameter can be whatever you want to route after your callback. Change as you would like.

> NOTE: Only need the route names if configuring `redirect_uri` in the portal.

### Front End

[](#front-end)

It's best to have an Office 365 button on your login webpage that routes to `route('azure.login')`. This can be as simple as an anchor tag like this ``

Extended Installation
---------------------

[](#extended-installation)

The out-of-the-box implementation let's you login users. However, let's say we would like to store this user into a database, as well as login the user in with Laravel Auth. There are two callbacks that are recommended to extend from the Azure class called `success` and `fail`. The following provides information on how to extend the Root Laravel Azure Middleware Library:

1. To get started (assuming we've followed the [Normal Installation](#normal-installation) directions), create a file called `AppAzure.php` in the `App\Http\Middleware` folder. You can either do this through `artisan` or manually.
2. Add this as a starting point in this file:

```
