Php 如何使用Laravel验证来自Microsoft Azure AD的数据并将其重定向到主页?
我正在尝试用我的laravel web应用程序验证Microsoft Azure广告。现在我指的是。我设法从microsoft azure广告中检索数据,但问题是它没有重定向到/home视图,而是重定向到login视图 我有一个想法,那就是链接来自微软的电子邮件和来自模型的电子邮件,这样它就可以直接进入主页。但我不知道如何将Microsoft数据(从提供商)传递到控制器。下面的代码(在Provider中)是我到目前为止所做的Php 如何使用Laravel验证来自Microsoft Azure AD的数据并将其重定向到主页?,php,laravel,azure-active-directory,single-sign-on,saml-2.0,Php,Laravel,Azure Active Directory,Single Sign On,Saml 2.0,我正在尝试用我的laravel web应用程序验证Microsoft Azure广告。现在我指的是。我设法从microsoft azure广告中检索数据,但问题是它没有重定向到/home视图,而是重定向到login视图 我有一个想法,那就是链接来自微软的电子邮件和来自模型的电子邮件,这样它就可以直接进入主页。但我不知道如何将Microsoft数据(从提供商)传递到控制器。下面的代码(在Provider中)是我到目前为止所做的 namespace App\Providers; use Illumi
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
{
protected $namespace = 'App\Http\Controllers';
public const HOME = '/home';
public function register()
{
//
}
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);
// $user = User::where('sso_user_id', $inputs['sso_user_id'])->where('email', $inputs['email'])->first();
// if(!$user){
// $res = PortalUser::store($inputs);
// if($res['status'] == 'success'){
// $user = $res['data'];
// Auth::guard('web')->login($user);
// }else{
// Log::info('SAML USER Error '.$res['messages']);
// }
// }else{
Auth::guard('web')->login($user);
// }
});
}
}
谁能在这个问题上帮助我。非常感谢。我的同事在这方面帮助了我,下面是他将Microsoft电子邮件与模型中的电子邮件链接的解决方案
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();
}
});
}
}