Credential Management
Credential Management Level 1
- Web サイトが UA に資格情報をリクエストし、UA がそれを使用できるようにする API
- スキームがダウングレードする場合はクレデンシャルを共有してはいけない(MUST NOT)
- 呼び出された Origin と Credential の Origin を比較して決定される
- CSP で保護することが推奨されている
- Secure Context のみで利用可能
- Timing Attack 防止のため、回数に制限もかける (SHOULD)
<html>
<body>
<form action="/login.php" method="post" id="login">
<input name="username" />
<input type="password" name="password" />
<button type="submit">Login</button>
</form>
<button onclick="autoLogin()">Auto Login</button>
<script>
function autoLogin() {
// navigator.credentials.get({ 'password': true }).then(credential => { if (credential) { console.log(credential); } else { console.log("has not credentials"); }})
navigator.credentials
.get({ 'password': true })
.then(credential => {
if (!credential) { return; }
if (credential.type == 'password') {
document.querySelector('input[name=username]').value = credential.id;
document.querySelector('input[name=password]').value = credential.password;
document.getElementById('login').submit();
}
});
}
</script>
</body>
</html>