Did you manage to solve?
Jan 10, 2020
4
Level 9
Laravel Azure AD Authentication redirect me back to Login Page
I am using Laravel-5.8 for User Azure AD Authentication. I installed this package:
composer require socialiteproviders/microsoft-azure
"socialiteproviders/microsoft-azure": "^3.0",
I also did the configuration. The regular Login from database is working perfecting, but I have issues with the Laravel microsoft-azure integration.
Login Controller
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/dashboard';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectToProvider()
{
return Socialite::with('azure')->redirect();
}
public function handleProviderCallback()
{
$user = Socialite::with('azure')->user();
}
login.blade
<form class="login-form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class=" w3l-form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label>Username:</label>
<div class="group">
<i class="fas fa-user"></i>
<input id="email" type="text" class="form-control" name="email" placeholder="Email" required autofocus>
<div>
</div>
</div>
</div>
<div>
@if ($errors->has('email'))
<span class="help-block" style="color: red">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class=" w3l-form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label>Password:</label>
<div class="group">
<i class="fas fa-unlock"></i>
<input id="password" type="password" class="form-control" name="password" placeholder="Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<button type="submit">Login</button>
<a href="{{ route('azure.login') }}" class="btn btn-primary"> Azure Login</a>
</form>
route/web.php
Route::get('login/azure', 'Auth\LoginController@redirectToProvider')->name('azure.login');
Route::get('login/azure/callback', 'Auth\LoginController@handleProviderCallback');
Route::get('/dashboard', 'HomeController@index')->name('dashboard');
config/services
'azure' => [
'client_id' => env('AZURE_KEY'),
'client_secret' => env('AZURE_SECRET'),
'redirect' => env('AZURE_REDIRECT_URI')
],
.env
AZURE_KEY= something
AZURE_SECRET= something
AZURE_REDIRECT_URI= http://localhost:8888/salesportal/dashboard
config/app
\SocialiteProviders\Manager\ServiceProvider::class,
For the Redirect URI, In Azure portal->App registrations->find your application->Authentication
I have
http://localhost:8888/salesportal/dashboard
When I clicked on Azure Login button, it redirected me back to Login page:
http://localhost:8888/salesportal/login
How do I resolve this?
Thank you.
Please or to participate in this conversation.