Jump to content

Find 2Fa/two-factor auth codes in Messages


Recommended Posts

Safari automatically reads your text messages and asks you to auto-fill any two-factor codes it finds:

 

image.png.a666f16720983b65664d549cda0567d1.png

 

I don't use Safari (I use Chrome) and I was sick of having to manually type the codes from my messages. This workflow reads your message history and finds the most recent 5, 6, 7, or 8 digit two-factor codes. When you select a code and press <enter> it is copied to your clipboard, or you can press <⌘+enter> and it will copy the code to your clipboard and paste it into the active application.

 

image.png.02b033b0e0d0536ec0829beccca296b1.png

 

Keyword: 2fm

Download the latest version: https://github.com/squatto/alfred-imessage-2fa/releases/latest/download/iMessage.2FA.alfredworkflow

GitHub: https://github.com/squatto/alfred-imessage-2fa

Packal: http://www.packal.org/workflow/imessage-2fa

Link to post

On my machine (High Sierra), I get the following error:

Fatal error: Declaration of Carbon\Translator::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale) in /Users/username/Dropbox/Config/Alfred 4/Alfred.alfredpreferences/workflows/user.workflow.3238863D-7399-4C90-A171-D38E111D9932/vendor/nesbot/carbon/src/Carbon/Translator.php on line 18

Also, from the README:

Quote

This was developed for Alfred 4, but it should work with Alfred 3 as well.

 

I haven't checked, but if you made the workflow with Alfred 4 (and it sounds like this is the case), it isn't compatible with Alfred 3, even if it doesn't use any Alfred 4-only features. Just saving a workflow makes it incompatible with earlier major versions of Alfred.

Edited by deanishe
Link to post
20 hours ago, deanishe said:

On my machine (High Sierra), I get the following error:


Fatal error: Declaration of Carbon\Translator::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale) in /Users/username/Dropbox/Config/Alfred 4/Alfred.alfredpreferences/workflows/user.workflow.3238863D-7399-4C90-A171-D38E111D9932/vendor/nesbot/carbon/src/Carbon/Translator.php on line 18

Also, from the README:

 

I haven't checked, but if you made the workflow with Alfred 4 (and it sounds like this is the case), it isn't compatible with Alfred 3, even if it doesn't use any Alfred 4-only features. Just saving a workflow makes it incompatible with earlier major versions of Alfred.

 

Thank you for letting me know about this! What version of PHP are you running? That's the result of that error. I will likely need to bring in an earlier version of a package to lower the PHP version that's required. Easily done. Or, I may just remove the Carbon library dependency entirely. It's only there to give you a relative timestamp ("2h ago"). A simple date and time would work just as well.

 

Regarding the Alfred version, that's good to know about the workflow export format. I'll adjust the message to indicate that it's only for Alfred 4.

 

Thank you!

Link to post
58 minutes ago, squatto said:

What version of PHP are you running?

 

7.1.16 (High Sierra).

 

59 minutes ago, squatto said:

Or, I may just remove the Carbon library dependency entirely. It's only there to give you a relative timestamp ("2h ago")

 

Probably the best idea. That's an awfully big dependency for such a trivial feature. It's pretty easy to write a function for that, too.

Link to post

That works. Thanks very much.

 

Have you considered adding a Snippet Trigger? I'm not sure if it would work super-well everywhere (I imagine quite a few 2FA input fields are set to digits only), but it would be very handy where it did work.

Link to post
Quote

 

[12:29:36.009] Logging Started...

[12:29:45.107] iMessage 2FA[Script Filter] Queuing argument ''

[12:29:45.276] iMessage 2FA[Script Filter] Script with argv '(null)' finished

[12:29:45.280] ERROR: iMessage 2FA[Script Filter] Code 255: Fatal error: Uncaught PDOException: SQLSTATE[HY000] [14] unable to open database file in /Users/Username/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F5219FED-7165-4B09-AEA1-B2069F06B509/find-messages.php:11

Stack trace:

#0 /Users/Username/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F5219FED-7165-4B09-AEA1-B2069F06B509/find-messages.php(11): PDO->__construct('sqlite:/Users/U…’)

#1 {main}

  thrown in /Users/Username/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F5219FED-7165-4B09-AEA1-B2069F06B509/find-messages.php on line 11

[12:29:45.281] ERROR: iMessage 2FA[Script Filter] JSON error: JSON text did not start with array or object and option to allow fragments not set. in JSON:

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [14] unable to open database file in /Users/Username/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F5219FED-7165-4B09-AEA1-B2069F06B509/find-messages.php:11

Stack trace:

#0 /Users/Username/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F5219FED-7165-4B09-AEA1-B2069F06B509/find-messages.php(11): PDO->__construct('sqlite:/Users/U...')

#1 {main}

  thrown in /Users/Username/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F5219FED-7165-4B09-AEA1-B2069F06B509/find-messages.php on line 11

 

 

Debug log above

 

UPDATE: For some reason my permissions got reset and didn't have full disk access. Works now.

 

However, Google 2FA is not automatically detected in search results - would love to know how to configure it to search for this. Cheers!

Edited by Cheah
Link to post
4 hours ago, Cheah said:

However, Google 2FA is not automatically detected in search results - would love to know how to configure it to search for this. Cheers!

 

The workflow searches your Messages.app history for messages that look like they contain a 2FA code. If you posted an example Google 2FA message or two, that would probably make it a lot easier for @squatto to update the workflow accordingly.

 

If you want to adjust your own copy, you'll need to edit the SQL query and regular expression to also match Google 2FA messages.

Link to post
On 1/30/2020 at 2:54 PM, deanishe said:

That works. Thanks very much.

 

Have you considered adding a Snippet Trigger? I'm not sure if it would work super-well everywhere (I imagine quite a few 2FA input fields are set to digits only), but it would be very handy where it did work.

 

I'll check into that. My only concern with requiring a snippet to be typed into an input field is that many 2fa code inputs are numeric-only, so a prefix to trigger the snippet won't work. I'll see what options there are though.

Link to post
On 2/1/2020 at 10:32 AM, Cheah said:

 

Debug log above

 

UPDATE: For some reason my permissions got reset and didn't have full disk access. Works now.

 

However, Google 2FA is not automatically detected in search results - would love to know how to configure it to search for this. Cheers!

 

Thanks for checking into that and for the update on what was happening. I'll make a note to check read permissions on the database file before attempting to run the query.

 

Are the Google 2FA codes like "G-000000"? "G-" and then 6 digits? I could add that in to the matches.

Link to post

I just released v1.2.0 of the workflow, which adds comprehensive error checking and reporting and adds support for Google 2FA codes.

 

Thanks @Cheah for the feedback and for the suggestion!

 

Latest release: https://github.com/squatto/alfred-imessage-2fa/releases/download/v1.2.0/iMessage.2FA.alfredworkflow

Edited by squatto
Linking the release URL
Link to post
  • 2 weeks later...

Thank you! I have wanted something like this for years to move 2FA codes from Messages into my VPN app. Works perfectly and I can do every step without taking my hands off the keyboard. LOVE IT.

 

I don't know if this is possible or if anyone wants it besides me, but I have been using SMS to Google Voice for some 2FA notifications (since SMS to a SIM card is not really secure. etc.) and it would be even more awesome if there was a variant that could extract a 2FA code from Google Voice running in a browser window. 

Link to post
19 minutes ago, Ben428 said:

a variant that could extract a 2FA code from Google Voice running in a browser window

 

FWIW, that's not so much a variant as a completely different thing altogether.

Edited by deanishe
Link to post
  • 4 months later...
Posted (edited)

I just released version 1.2.1 of the workflow, which fixes a bug that prevented codes from being found if they were followed by a period: "your code is 12345."

 

Thanks to @tmm for the bug report and @manonstreet for submitting the fix!

 

Latest release: https://github.com/squatto/alfred-imessage-2fa/releases/download/v1.2.1/iMessage.2FA.alfredworkflow

Edited by squatto
Make the link...a link
Link to post
  • 3 weeks later...

I just released version 1.2.2 of the workflow, which changes the input method from a system paste to simulated keystrokes. This fixes an issue with websites that monitor keystrokes and don't consider pasting to be a valid input (e.g. Wells Fargo online banking)

 

Thanks to @cmer for submitting the changes!

 

Latest release: https://github.com/squatto/alfred-imessage-2fa/releases/download/v1.2.2/iMessage.2FA.alfredworkflow

Link to post
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...