Поскольку атрибут data-post-action
не будет работать, мне пришлось запускать каждую часть аутентификации по одному и тому же маршруту / методу.Другой ключевой частью было добавление формы с csrf_token()
для передачи идентификатора пользователя после первоначальной аутентификации.В Laravel вы не можете публиковать данные без csrf_token.Все ключи DUO хранятся в файле .env.
Маршрут:
Route::any('/login/duo', 'AuthController@duoAuthentication');
Метод контроллера:
public function duoAuthentication()
{
if (isset($input['sig_response'])) {
$userAuthenticated = Web::verifyResponse($ikey, $skey, $akey, $input['sig_response']);
if ($userAuthenticated) {
Sentry::login(Sentry::findUserById($input['user_id']));
return Redirect::to('/dashboard');
}
}
$username = $input['email'];
$sig_request = Web::signRequest($ikey, $skey, $akey, $username);
return view('users::duo', [
'host' => "api-5ccb0890.duosecurity.com",
'sig_request' => $sig_request,
'post_action' => '/user/redirect/to/dashboard',
'user_id' => $usercheck['id'],
]);
}
Шаблон Blade:
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12">
<script>
Duo.init({
'host': '{{ $host }}',
'sig_request': '{{ $sig_request }}'
});
</script>
<iframe id="duo_iframe">
</iframe>
<form id="duo_form" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="user_id" value="{{ $user_id }}">
</form>
<style>
#duo_iframe {
width: 100%;
min-width: 304px;
max-width: 620px;
height: 330px;
border: none;
}
</style>
</div>
</div>
</div>