#javascript #saml #saml-2.0 #fetch-api #opensaml
Вопрос:
При нажатии кнопки «Отправить» на странице входа в систему моего приложения я вызываю JavaScript, который использует API выборки для отправки вызова в конечную точку единого входа IDP. Ответ на почтовый вызов-это html-страница с данными формы, которые должны автоматически отправляться браузером для выполнения почтового вызова и перенаправления пользователя на этот URL. (Конечная точка единого входа IDP отвечает за создание ответа SAML, и создается html-форма с данными SAMLResponse.)
Я не в состоянии этого достичь. Не мог бы кто-нибудь, пожалуйста, помочь?
Мой JS-это-
if (document.querySelector) {
// add onSubmit function to the login form
document.getElementById("login_form").addEventListener("submit", function (e) {
e.preventDefault() // need this, or the first call will fail
let login = {};
login.username = document.getElementById("username").value
login.password = document.getElementById("password").value
fetch('/portal/login', {
method: 'POST',
redirect: "follow",
headers: new Headers({
'Content-Type': 'application/json'
}),
body: JSON.stringify(login),
}).then(function (response) {
return response.text();
}).then(function (html) {
// This is the html data from our response
console.log(html);
document.body.innerHTML = html //**I think I need to change this part, not sure how.**
}).catch(function (err) {
console.info(err);
});
});
}
Данные ответа на публикацию fetch (response.text/html) —
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body onload="document.forms[0].submit()">
<noscript>
<p>
<strong>Note:</strong> Since your browser does not support JavaScript,
you must press the Continue button once to proceed.
</p>
</noscript>
<form action="httpsamp;#x3a;amp;#x2f;amp;#x2f;test.comamp;#x2f;session-apiamp;#x2f;protocolamp;#x2f;saml2amp;#x2f;sso" method="post">
<div>
<input type="hidden" name="RelayState" value="DATA"/>
<input type="hidden" name="SAMLResponse" value="DATA"/>
</div>
<noscript>
<div>
<input type="submit" value="Continue"/>
</div>
</noscript>
</form>
</body>
</html>