Laravel 4.1.23 サイトでhttps://github.com/ChristianRiesen/otpを使用して 2 要素認証を統合する作業を行っています。シークレットは正常に生成され、QR コード画像も生成され、Google Authenticator は画像。
ただし、Google Authenticator アプリケーション内で iPhone で生成されたコードは検証されません。README.md の例に従いました。
私のコントローラーには、次のようなコードがあります。
$secret = GoogleAuthenticator::generateRandom();
$url = GoogleAuthenticator::getQrCodeUrl('totp', 'MySite:'.Auth::user()->email, $secret);
// Save the secret with the user's data
if (!Auth::user()->secret) {
Auth::user()->secret = $secret;
Auth::user()->save();
}
return View::make('2fa')->with('secret', $secret)->with('url', $url);
次に、私のビュー (2fa.blade.php) には、次のようなコードがあります。
<strong>Secret Key:</strong> {{ $secret }}
<strong>QR Code</strong> <br/>
<img src="{{ $url }}" />
<form action="/confirm_key" method="post">
<label for="key">Enter the generated key:</label>
<input type="text" name="key" id="key"/>
<input type="submit" id="submit" value="Confirm Key"/>
</form>
それはすべて機能しているようです。フォームは、次のコントローラー関数に投稿します。
public function postTwoFactorAuthentication() {
// Now how to check
$otp = new Otp();
if ($otp->checkTotp(Base32::decode(Auth::user()->secret), Input::get('key'))) {
return 'Verified!';
}
// Wrong key
else {
return 'Invalid key!'
}
}
これはレポの使用例にかなり厳密に従っていますが、キー (トークン) は検証されません。ここで何か不足していますか?Laravelは何かを台無しにしていますか?
どんな助けでも大歓迎です。