Laravel and Azure ad SSO
The settings were incorrect as mentioned in the comment below the question
How to Authenticate the data from Microsoft Azure AD using Laravel and redirect it to Home?
My colleague help me on this and below are the solution where he link the Microsoft email with email from the model
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Aacotroneo\Saml2\Events\Saml2LoginEvent;
use App\User;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class SAML2ServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
protected $namespace = 'App\Http\Controllers';
public const HOME = '/home';
public function register()
{
//
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
Event::listen('Aacotroneo\Saml2\Events\Saml2LoginEvent', function (Saml2LoginEvent $event) {
// dd($event);
// $messageId = $event->getSaml2Auth()->getLastMessageId();
// Add your own code preventing reuse of a $messageId to stop replay attacks
$user = $event->getSaml2User();
// $userData = [
// 'id' => $user->getUserId(),
// 'attributes' => $user->getAttributes(),
// 'assertion' => $user->getRawSamlAssertion()
// ];
// dd($userData);
$inputs = [
'sso_user_id' => $user->getUserId(),
'username' => $user->getAttribute('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name'),
'email' => $user->getAttribute('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'),
'first_name' => $user->getAttribute('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname'),
'last_name' => $user->getAttribute('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname'),
'password' => Hash::make('anything'),
];
// dd($inputs['email'][0]);
$user = User::where('email', $inputs['email'][0])->first();
// dd($user->id);
if(!$user){
return view ('404');
}else{
Auth::loginUsingId($user->id);
session()->regenerate();
}
});
}
}
How do I get azure ad auth up and running?
You could refer to this link to configure your web app to use Azure AD login.
Note: In step 4, I recommend you to create a new AD App(app registration), not select an existing app
, when using the first one, azure will help you configure some settings automatically, it can save unnecessary trouble.
Related Topics
PHP Array_Intersect() Efficiency
PHP Using Declare? What Is a Tick
How to Http Post Special Chars in Swift
Pdo: Call to a Member Function Fetch() on a Non-Object
Mail(): Smtp Server Response: 550 the Address Is Not Valid Error on Hmailserver
Laravel Eloquent Orm Transactions
Difference Between Array_Push() and $Array[] =
How to Generate a Custom Menu/Sub-Menu System Using Wp_Get_Nav_Menu_Items in Wordpress
Php: How to Get Associative Array Key from Numeric Index
Parse Error: Syntax Error, Unexpected '' (T_Encapsed_And_Whitespace)
Simple Xml Add Namespaced Child
Mysqli Prepared Statement Num_Rows Returns 0 While Query Returns Greater Than 0
Remove/Replace the Username Field with Email Using Fosuserbundle in Symfony2/Symfony3
Laravel: Where to Store Global Arrays Data and Constants
Inspect Xml Created by PHP Soapclient Call Before/Without Sending the Request