Skip to content

Commit 485a7b4

Browse files
author
Dan Jewett
committed
customized redirect
1 parent 28ef5b2 commit 485a7b4

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,33 @@ class AppAzure extends Azure
111111

112112
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.
113113

114+
#### Custom Redirect
115+
116+
As of v0.6.0, we added the ability to customize the redirect method. For example, if the session token's expire, but the user is still authenticated, we can check for that with this example:
117+
118+
```php
119+
<?php
120+
121+
namespace App\Http\Middleware;
122+
123+
use RootInc\LaravelAzureMiddleware\Azure as Azure;
124+
125+
class AppAzure extends Azure
126+
{
127+
protected function redirect($request)
128+
{
129+
if (Auth::user() !== null)
130+
{
131+
return $this->azure($request);
132+
}
133+
else
134+
{
135+
return redirect($this->login_route);
136+
}
137+
}
138+
}
139+
```
140+
114141
#### Different Login Route
115142

116143
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:

src/Azure.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function handle($request, Closure $next)
3636

3737
if (!$access_token || !$refresh_token)
3838
{
39-
return redirect($this->login_route);
39+
return $this->redirect($request);
4040
}
4141

4242
$client = new Client();
@@ -98,6 +98,11 @@ public function azurecallback(Request $request)
9898
return $this->success($request, $access_token, $refresh_token, $profile);
9999
}
100100

101+
protected function redirect($request)
102+
{
103+
return redirect($this->login_route);
104+
}
105+
101106
protected function success($request, $access_token, $refresh_token, $profile)
102107
{
103108
return redirect("/");

0 commit comments

Comments
 (0)