MFAとパスワードレス
🔥 Vibe プロンプト
「TOTP MFA、WebAuthnパスキー、リスクベース認証を実装。」
TOTP
import pyotp
secret = pyotp.random_base32()
totp = pyotp.TOTP(secret)
uri = totp.provisioning_uri(name="alice@example.com", issuer_name="MyApp")
# QRコードを生成してユーザーに見せる
# ユーザーがコードを入力
code = input("TOTPコードを入力: ")
if totp.verify(code):
print("✅ TOTP有効!")
WebAuthn(パスキー)
const credential = await navigator.credentials.create({
publicKey: {
challenge: new Uint8Array([...]),
rp: { name: "MyApp", id: "example.com" },
user: { id: new Uint8Array([1,2,3]), name: "alice@example.com" },
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
authenticatorSelection: {
residentKey: "required",
userVerification: "required"
}
}
});
リスクベース認証
def calculate_risk(user, request):
score = 0
if request.geo.country != user.known_countries: score += 30
if request.user_agent not in user.known_devices: score += 20
if is_vpn_or_tor(request.ip): score += 25
if user.failed_logins_last_hour > 3: score += 10
if score > 70: return "BLOCK"
elif score > 40: return "CHALLENGE_MFA"
else: return "ALLOW"
MFA方法比較
| 方法 | UX | セキュリティ | |------|-----|------------| | TOTP | 中 | 高 | | SMS | 良い | 低 | | Push通知 | 良い | 高 | | WebAuthn/Passkeys | 最高 | 最高 |
ベストプラクティス
- WebAuthnを優先(最高のUX+セキュリティ)
- TOTPをフォールバック
- SMS MFAは避ける
- 管理操作にはMFA必須
- 信頼済みデバイスを記憶
重要なポイント
- コアコンセプトをしっかり理解する
- ハンズオンコード例で実践する
- 実世界の問題に応用する
- 演習で知識を強化する
さらに学ぶ
- 公式ドキュメント
- GitHubのオープンソースプロジェクト
- コミュニティフォーラムとディスカッション
- 関連コースとチュートリアル