You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
3. In our `App\Http\Kernel.php` add `'azure' => \RootInc\LaravelAzureMiddleware\Azure::class,` most likely to the `$routeMiddleware` array.
15
15
4. In our `.env` add `TENANT_ID, CLIENT_ID, CLIENT_SECRET and RESOURCE`. We can get these values/read more here: https://portal.azure.com/
16
-
5. Add the `azure` middleware to your route groups (or wherever) and enjoy :tada:
17
-
6. If you need custom callbacks, see #Extended Installation.
16
+
5. Add the `azure` middleware to your route groups on any routes that needs protected by auth and enjoy :tada:
17
+
6. If you need custom callbacks, see [Extended Installation](#extended-installation).
18
18
19
19
## Routing
20
20
21
21
`Route::get('/login/azure', '\RootInc\LaravelAzureMiddleware\Azure@azure');` First parameter can be wherever you want to route the azure login. Change as you would like.
22
22
23
23
`Route::get('/login/azurecallback', '\RootInc\LaravelAzureMiddleware\Azure@azurecallback');` First parameter can be whatever you want to route after your callback. Change as you would like.
24
24
25
-
## Front End
25
+
###Front End
26
26
27
27
It's best to have an Office 365 button on our login webpage that routes to `/login/azure` (or whatever you renamed it to). This can be as simple as an anchor tag like this `<a href="/login/azure" class="officeButton"></a>`
28
28
29
29
## Extended Installation
30
30
31
-
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. 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:
31
+
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 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:
32
32
33
-
1. To get started (assuming we've followed the #Normal Installation directions), create a file called `AppAzure.php` in the `App\Http\Middleware` folder. You can either do this through `artisan` or manually.
33
+
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.
4. Finally, update `Kernel.php`'s `azure` key to be `'azure' => \App\Http\Middleware\AppAzure::class,`
73
73
74
+
### Callback on Every Handshake
75
+
76
+
As of v0.4.0, we added a callback after every successful handle (handshake). The default is to simply call the `$next` closure. However, let's say we want to store a Singleton of a user. Here's an example of how to go about that:
77
+
78
+
```php
79
+
<?php
80
+
81
+
namespace App\Http\Middleware;
82
+
83
+
use Closure;
84
+
85
+
use RootInc\LaravelAzureMiddleware\Azure as Azure;
86
+
87
+
use App\User;
88
+
89
+
class AppAzure extends Azure
90
+
{
91
+
protected function handlecallback($request, Closure $next, $access_token, $refresh_token)
Building off of our previous example from [Extended Installation](#extended-installation), we have a `user_id` set in the session. We can use this id to query against the user model. Once we have the user model, we can setup the singleton to return the user. The callback should call the closure, `$next($request);` and return it. In our case, the default implementation redirects to `/`, so we call the parent here.
110
+
111
+
#### Different Login Route
112
+
113
+
As of v0.4.0, we added the ability to change the `$login_route` in the middelware. Building off [Extended Installation](#extended-installation), in our `AppAzure` class, we can simply set `$login_route` to whatever. For example:
114
+
115
+
```php
116
+
<?php
117
+
118
+
namespace App\Http\Middleware;
119
+
120
+
use RootInc\LaravelAzureMiddleware\Azure as Azure;
121
+
122
+
class AppAzure extends Azure
123
+
{
124
+
protected $login_route = "/";
125
+
}
126
+
```
127
+
128
+
The above would now set `$login_route` to `/` or root.
129
+
74
130
## Contributing
75
131
76
-
TODO
132
+
Thank you for considering contributing to the Laravel Azure Middleware! To encourage active collaboration, we encourage pull requests, not just issues.
133
+
134
+
If you file an issue, the issue should contain a title and a clear description of the issue. You should also include as much relevant information as possible and a code sample that demonstrates the issue. The goal of a issue is to make it easy for yourself - and others - to replicate the bug and develop a fix.
0 commit comments