Skip to content

Instantly share code, notes, and snippets.

@yudukikun5120
Last active February 6, 2024 03:21
Show Gist options
  • Save yudukikun5120/61613b115b6c77484efba3abd2f86e39 to your computer and use it in GitHub Desktop.
Save yudukikun5120/61613b115b6c77484efba3abd2f86e39 to your computer and use it in GitHub Desktop.
Automatic Login for the Unified Authentication System of the University of Tsukuba
// ==UserScript==
// @name Automatic Login for the Unified Authentication System of the University of Tsukuba
// @version 1.0
// @description Automatic Login for the Unified Authentication System of the University of Tsukuba
// @match https://idp.account.tsukuba.ac.jp/idp/profile/SAML2/Redirect/SSO*
// @grant none
// ==/UserScript==
(function () {
'use strict';
navigator.credentials.get({
password: true,
mediation: "silent"
})
.then(cred => {
if (cred) {
setTimeout(() => {
const formData = new FormData();
formData.append('j_username', cred.id);
formData.append('j_password', cred.password);
formData.append('_eventId_proceed', 'Login');
// フォームを作成して追加
const form = document.createElement('form');
form.method = 'POST';
form.action = location.pathname + location.search;
form.style.display = 'none'; // フォームを非表示にする
document.body.appendChild(form);
// FormDataの内容をフォームに追加
for (const pair of formData.entries()) {
const input = document.createElement('input');
input.type = 'hidden';
input.name = pair[0];
input.value = pair[1];
form.appendChild(input);
}
// フォームをsubmitする
form.submit();
}, 1000);
} else {
console.error('認証情報が取得できませんでした');
// エラー処理を記述する
return Promise.reject('認証情報が取得できませんでした');
}
})
.catch(error => {
console.error('エラーが発生しました', error);
// エラー処理を記述する
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment