noblemfd
2 months ago
354
5
Laravel

Laravel - Authenticating Using Azure AD and Database

Posted 2 months ago by noblemfd

Hello guys, I am trying to add Authentication with Azure AD to my Laravel Web Application, hosted on Digital Ocean.

Already I have done this for the Database Authentication, but I need Azure AD Authentication:

Model

class User extends Authenticatable
{
    protected $hidden = [
        'password',
        'remember_token',
    ];
    
    protected $dates = [
        'updated_at',
        'created_at',
        'email_verified_at',
        'last_login_at',
    ];

    protected $fillable = [
        'name', 
        'first_name',
        'last_name',
        'email', 
        'email_verified_at',
        'password', 
        'updated_at',
        'created_at',
        'last_login_at',
        'creation_type'
    ];
}

Controller

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyUserRequest;
use App\Http\Requests\StoreUserRequest;
use App\Http\Requests\UpdateUserRequest;
use App\Role;
use App\User;

class UsersController extends Controller
{
    public function index()
    {
        abort_unless(\Gate::allows('user_access'), 403);

        $users = User::all();

        return view('admin.users.index', compact('users'));
    }

    public function create()
    {
        abort_unless(\Gate::allows('user_create'), 403);

        $roles = Role::all()->pluck('title', 'id');

        return view('admin.users.create', compact('roles'));
    }

    public function store(StoreUserRequest $request)
    {
        abort_unless(\Gate::allows('user_create'), 403);

        $user = User::create($request->all());
        $user->roles()->sync($request->input('roles', []));

        return redirect()->route('admin.users.index');
    }
}

I started using Laravel about 6 months ago. I am using Laravel-5.8 for my web application that will be Role and Permission based. The application is multiple company. Some of the users have their details in AZURE AD while others have theirs in the database. Already I have done the database authentication, where users can login based on the database details. But I want to achieve the following:

  1. How do I make users login with Azure AD Authentication? I have never done this before.
  2. How do I import and save the users credentials into the Application Database.
  3. If the detail doesn't exits, it can send an invite to their Azure through the email.

I will appreciate any sample.

Thanks

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