twofas / 2fas-android

Source code for 2FAS Android app
GNU General Public License v3.0
868 stars 64 forks source link

Option to import/export from/to a plain text file with a list of otpauth URIs #100

Open timkgh opened 7 months ago

timkgh commented 7 months ago

Option to import/export from/to a plain text file with a list of otpauth URIs. Take a look at Aegis. Thank you.

robsonsobral commented 6 months ago

Given that Authy will shut down its desktop app in August 2024 , the window to migrate will close soon.

timkgh commented 6 months ago

Given that Authy will shut down its desktop app in August 2024 , the window to migrate will close soon.

You can use https://github.com/alexzorin/authy or https://github.com/jmhobbs/authy-cli or other similar tools, you do not need to rely on the desktop app workarounds.

robsonsobral commented 6 months ago

Thank you, @timkgh, but Authy is banning accounts from unofficial clients.

Thank you!

timkgh commented 6 months ago

I didn't know, thank you for pointing it out. Everyone should rush and get a copy of their secrets, even if they continue to use the Authy apps. For new entries, also add it to another alternate app.

impredicative commented 6 months ago

How am I supposed to import into 2fas the export of alexzorin/authy?

timkgh commented 6 months ago

How am I supposed to import into 2fas the export of alexzorin/authy?

A few options:

impredicative commented 6 months ago

you can import the list into Aegis, export in Aegis format from there and then import into 2FAS.

If Aegis supports both an import and an export, then why do I need 2fas? I could then just use Aegis.

impredicative commented 6 months ago

you can import the list into Aegis, export in Aegis format from there and then import into 2FAS.

I just realized that in the 2fas app, I can import the output of alexzorin/authy as "Authenticator Pro". This worked fine except for some accounts that were using an old "@protonmail.ch" email address. I then manually reviewed (and edited as needed) all entries now to ensure everything was correct.

KobeW50 commented 6 months ago

Similar to #88

mr-september commented 6 months ago

you can import the list into Aegis, export in Aegis format from there and then import into 2FAS.

I just realized that in the 2fas app, I can import the output of alexzorin/authy as "Authenticator Pro". This worked fine except for some accounts that were using an old "@protonmail.ch" email address. I then manually reviewed (and edited as needed) all entries now to ensure everything was correct.

Could you please explain further? The output I get from alexzorin/authy is a .json file. 2FAS import from Authenticator Pro expects a .txt file. If I simply re-name the .json to .txt, that does not work. No errors pop up, but also no tokens get imported.

timkgh commented 6 months ago

Export in Key URI Format, not JSON. It's just a plain text file with 1 URI per line. https://github.com/alexzorin/authy?tab=readme-ov-file#applications Your file should look like a bunch of lines similar to this:

otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
otpauth://totp/Example:bob@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Google
...
mr-september commented 6 months ago

Thanks, I just realized that I was following a different guide back when I did the export (it was using some browser dev tools). The drawback of alexzorin/authy is the lack of pre-compiled Windows release. It's not trivial for most users to "just" compile it from source.

At this stage I think it's easier to ask chatgpt to generate a .json to URI python script. It is a little strange how much 2FAS devs are dragging their feet on this seemingly trivial compatibility feature.

impredicative commented 6 months ago

The drawback of alexzorin/authy is the lack of pre-compiled Windows release.

One can run it on a Linux VM.

mr-september commented 6 months ago

That's still a lot of hassle. Here's a working python script for real users:

import json

def convert_json_to_uri(input_file, output_file):
    # Read the JSON file
    with open(input_file, 'r') as file:
        data = json.load(file)

    # Extract the 'totp' values
    totp_values = [item['login']['totp'] for item in data['items'] if 'login' in item and 'totp' in item['login']]

    # Write the 'totp' values to a new line in the output text file
    with open(output_file, 'w') as file:
        for totp in totp_values:
            file.write(totp + '\n')

# Example usage in Windows
input_path = r'D:\OneDrive\Desktop\input.json'
output_path = r'D:\OneDrive\Desktop\output.txt'

convert_json_to_uri(input_path, output_path)

Just change your paths and click "Run" in VSCode or whatever.

EDIT: Just confirmed that it works with the Authenticator Pro import route, as discussed above.