如何使用 Laravel 验证来自 Microsoft Azure AD 的数据并将其重定向到主页?
How to Authenticate the data from Microsoft Azure AD using Laravel and redirect it to Home?
我正在尝试使用我的 laravel 网络应用验证 Microsoft Azure AD。目前我指的是 Azure Active Directory SSO with Laravel。我设法从 Microsoft Azure 广告中检索数据,但问题是它没有重定向到 /home 视图,而是重定向到登录视图。
我有一个想法,就是link微软发来的邮件和模型发来的邮件,这样就可以直接到首页了。但我不知道如何将 Microsoft 数据(从提供商)传递给控制器。下面的代码(在 Provider 中)是我到目前为止所做的。
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);
// }
});
}
}
谁能帮我解决这个问题。非常感谢。
我的同事帮我解决了这个问题,以下是他 link 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();
}
});
}
}
我正在尝试使用我的 laravel 网络应用验证 Microsoft Azure AD。目前我指的是 Azure Active Directory SSO with Laravel。我设法从 Microsoft Azure 广告中检索数据,但问题是它没有重定向到 /home 视图,而是重定向到登录视图。
我有一个想法,就是link微软发来的邮件和模型发来的邮件,这样就可以直接到首页了。但我不知道如何将 Microsoft 数据(从提供商)传递给控制器。下面的代码(在 Provider 中)是我到目前为止所做的。
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);
// }
});
}
}
谁能帮我解决这个问题。非常感谢。
我的同事帮我解决了这个问题,以下是他 link 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();
}
});
}
}