Search code examples
c#google-2fa

Is there a way to get current Google Authenticator 2FA key for a specific account (client-side)


I am searching for a way to obtain the current code in my Google Authenticator app. for a specific account.

Please note that I'm not looking for embedding Google 2FA to any of server-side application - I guess it has been already well-documented.

I am trying to get the same current code shown in my own Google 2FA app. (by providing my Google credientials ofcourse) so I can make my app fully automated even when logging in (to a specific system/website) without asking for the code each time I start the app.

Thanks by now.

UPDATE: Even if I can't find any answer or simply "there is no way", there is still a way even if it's too ugly.

Running an ios/android simulator (and configure it once by installing the Google Auth app) and simulate the mouse clicks over it and then capturing a screenshot and decoding the code from the image would be much of a work but also can actually work. I'm just trying to find a better way, if there is any.


Solution

  • You could solve this by generating the OTP code locally using a library such as OTP.Net. Simply save the secret locally, and add it to .gitignore if using git.

    Then you can make a code on demand like so:

    using OtpNet;
    var totp = new Totp(secretKey);
    var totpCode = totp.ComputeTotp();