13

https://github.com/chregu/GoogleAuthenticator.phpを使用して、作業中の Web アプリケーションの 2 要素認証を構築しました。すべてが秘密を生成して機能し、コードでさえ機能しました。今、私は別のサーバーで同じコードを設定し、新しい秘密鍵を生成し、それを Google 認証モバイル アプリに追加しました。モバイルで生成されたコードは一致しません。

両方のサーバーで結果を比較して掘り下げたところ、time() 関数が異なる時間 (1 時間の差) を返すことに気付き、2 番目のサーバー (Google コードが機能しなかった) を最初のサーバーと同じ時間に強制したところ、機能しました。だから私は本当に混乱していますこれはある種のタイムゾーンの問題ですか? これらのサーバーには独自のタイムゾーンが必要です。

回避策はありますか?

また、 https: //support.google.com/accounts/answer/185834?hl=enに従い、Google 認証アプリを同期しても機能しません。モバイル アプリで生成されたコードは、1 時間後に 2 番目のサーバーで動作します。誰でも私を助けてくれるか、別のアプローチを提案してもらえますか。

上記のライブラリに接続するために使用しているコードは次のとおりです

class googleAuthLibrary extends GoogleAuthenticator
{
    public function getSecretKey()
    {
        $secretKey = $this->generateSecret();

        return $secretKey;
    }

    public function getQRLink($username, $hostname, $secretKey)
    {
        $url = 'https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=';

        $qrCode = 'otpauth://totp/'.$username.'@'.$hostname.'?secret='.$secretKey;

        $url = $url.$qrCode;

        return $url;
    }

    public function getAuthCode($secretKey)
    {
        $authCode =$this->getCode($secretKey);

        return $authCode;
    }
}
4

1 に答える 1