noblemfd
1 month ago

Socialite Azure Login Failed in Laravel

Posted 1 month ago by noblemfd

I am using Laravel-5.8 for User Azure AD Authentication. I installed this package:

"socialiteproviders/microsoft-azure": "^3.0",

composer require socialiteproviders/microsoft-azure

I also did the configuration.

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;
  public function __construct()
  {
    $this->middleware('guest')->except('logout');
  }  
}    

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>
        <div class="forgot">
            <a href="{{ route('password.request') }}"> Forgot Password?</a>
            <p><input type="checkbox" value="remember-me" {{ old('remember') ? 'checked' : '' }}></p>
        </div>
        <button type="submit">Login</button>
    </form>

config/services

'azure' => [
'client_id' => env('AZURE_KEY'),
'client_secret' => env('AZURE_SECRET'),
'redirect' => env('AZURE_REDIRECT_URI')
],

.env

AZURE_KEY= 
AZURE_SECRET= 
AZURE_REDIRECT_URI= http://localhost:8888/login/microsoft/callback

config/app

\SocialiteProviders\Manager\ServiceProvider::class,

When I logged in, I got this error: Login failed

How do I resolve this?

Thank you

Please sign in or create an account to participate in this conversation.