PHP code example of rootinc / laravel-azure-middleware
1. Go to this page and download the library: Download rootinc/laravel-azure-middleware library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rootinc / laravel-azure-middleware example snippets
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Closure;
use RootInc\LaravelAzureMiddleware\Azure as Azure;
use Auth;
use Carbon\Carbon;
use App\User;
class AppAzure extends Azure
{
protected function handlecallback(Request $request, Closure $next, $access_token, $refresh_token)
{
$user = Auth::user();
$user->updated_at = Carbon::now();
$user->save();
return parent::handlecallback($request, $next, $access_token, $refresh_token);
}
}
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use RootInc\LaravelAzureMiddleware\Azure as Azure;
use Auth;
class AppAzure extends Azure
{
protected function redirect(Request $request)
{
if (Auth::user() !== null)
{
return $this->azure($request);
}
else
{
return parent::redirect($request);
}
}
}
namespace App\Http\Middleware;
use RootInc\LaravelAzureMiddleware\Azure as Azure;
class AppAzure extends Azure
{
protected $login_route = "/";
}
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use RootInc\LaravelAzureMiddleware\Azure as Azure;
use Auth;
class AppAzure extends Azure
{
//we could overload this if we wanted too.
public function getAzureUrl()
{
$url = $this->baseUrl . config('azure.tenant_id') . $this->route2 . "authorize?response_type=code&client_id=" . config('azure.client.id') . "&domain_hint=" . urlencode(config('azure.domain_hint')) . "&scope=" . urldecode(config('azure.scope'));
return Route::has('azure.callback') ? $url . '&redirect_uri=' . urlencode(route('azure.callback')) : $url;
}
public function azure(Request $request)
{
$user = Auth::user();
$away = $this->getAzureUrl();
if ($user)
{
$away .= "&login_hint=" . $user->email;
}
return redirect()->away($away);
}
}
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use RootInc\LaravelAzureMiddleware\Azure as Azure;
use Auth;
class AppAzure extends Azure
{
//this is the default behavior
//overwrite to meet your needs
protected function handleTesting(Request $request, Closure $next)
{
$user = Auth::user();
if (!isset($user))
{
return $this->redirect($request, $next);
}
return $this->handlecallback($request, $next, null, null);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.