2FA Verification Code Trigger?

Posted on
Mon Aug 15, 2022 7:45 pm
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

2FA Verification Code Trigger?

I recently started using your plugin again and I'm looking for a feature....

Is there a way to trigger off when the plugin needs to re-authenticate with apple?

That happened to me today... got the kids new phones set up. New GeoFences for all the schools, added some pushover notifications then went for a drive. No notifications. Then I realized that the devices haven't updated in over a week (but they were still showing as online and everything else looked fine). So, I would have to trigger an event or notification based on "device last updated" being outside of set parameter.

I tried to see if I could trigger if "device last updated" is greater than today's date or something.... didn't have much luck.

Since the "device last updated" is a string, I'm guessing it would be easier to write a python script based on the "timestamp" state which is an integer.

I'm guessing I could probably have a daily schedule that uses an "if python script return True" but I'm not too good with python date stuff.

I'm rambling now. Any point in the right direction would be much appreciated.

Bill
My Plugin: My People

Posted on
Mon Aug 15, 2022 8:27 pm
GlennNZ offline
User avatar
Posts: 1572
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: 2FA Verification Code Trigger?

Thanks.

Was considering the same thing - my development system is on a 2FA device and had a code request randomly the other day (after running for months authenicated without issue)

It just fails to authenicate (despite being a trusted Device - which should mean it doesn't)
& you need to reauthenicate/enter a new code.

Have been looking at this myself - waiting for the event to occur again to clearly update the code/catch it again - but may see if can use old logging to capture.

Then will setup Event/Trigger which is authenication fails type

Glenn

Posted on
Tue Aug 16, 2022 6:41 am
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: 2FA Verification Code Trigger?

Luckily I had a trigger that was updating an external CVS file with location data.... The last day it posted for any of the phones was on 7/25. Going back through the log on that day, I found one FFM Error. I'm guessing this is it because I see "HTTP....icloud... read timed out." on the last line.

Out of curiosity, did your's sign out on the same day? Wondering if it's something they pushed out from apple.

Code: Select all
2022-07-25 17:13:02.293   FindFriendsMini Error   Caught Exception
Traceback (most recent call last):
  File "plugin.py", line 801, in refreshData
    friendsdata = iLogin[1].friends.data
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/Plugins/iFindFriendsMini.indigoPlugin/Contents/Server Plugin/pyicloud/services/findmyfriends.py", line 33, in data
    self._data = self.refresh_data()
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/Plugins/iFindFriendsMini.indigoPlugin/Contents/Server Plugin/pyicloud/services/findmyfriends.py", line 26, in refresh_data
    req = self.session.post(self._friend_endpoint, data=fake_data, params=params)
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/sessions.py", line 520, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/Plugins/iFindFriendsMini.indigoPlugin/Contents/Server Plugin/pyicloud/base.py", line 81, in request
    response = super(PyiCloudSession, self).request(method, url, timeout=15, **kwargs )
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/sessions.py", line 477, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/sessions.py", line 587, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Application Support/Perceptive Automation/Indigo 2022.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/adapters.py", line 493, in send
    raise ReadTimeout(e, request=request)
ReadTimeout: HTTPSConnectionPool(host='p33-fmipweb.icloud.com', port=443): Read timed out. (read timeout=15)

Bill
My Plugin: My People

Posted on
Tue Aug 16, 2022 9:34 am
whmoorejr offline
User avatar
Posts: 763
Joined: Jan 15, 2013
Location: Houston, TX

Re: 2FA Verification Code Trigger?

My FFM just threw another error.... but as far as I can tell, all phones are still talking to the plugin. Looks near identical to the above error message.

I ran the "update data for all devices" action after the error, and everything updated.

A possible work-around using another plugin....
https://www.indigodomo.com/pluginstore/88/ "Timed Devices"

There is an "Alive Timer" Device that can monitor one of your FFM devices. You can set it to a duration (say 10 minutes). So as long as your FFM device has some form of update within that timeframe (like the default 5 minute refresh), then the alive timer will stay on. Then you set a trigger if the alive timer shuts off (which should indicate that the FFM device hasn't gotten an update in 10+ minutes) which should be an indicator that there might be an authentication problem.

Bill
My Plugin: My People

Posted on
Fri Aug 19, 2022 10:09 pm
GlennNZ offline
User avatar
Posts: 1572
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: 2FA Verification Code Trigger?

Hi

Looking at this now.

The error you have pasted is a pretty generic icloud timeout. Happens all the time - well relatively frequently - apple server down, maintenance etc. Should recover once issue over - as you found in the 2nd example.

The 2FA verification failed sequence is quite different.

Basically get this when authenication ends:
Code: Select all
2022-07-30 13:30:37.851   FindFriendsMini   ==================================================================================================================================
2022-07-30 13:30:37.852   FindFriendsMini   ==================================================================================================================================
2022-07-30 13:30:37.852   FindFriendsMini   Account requires a two step authentication:  Please see Plugin Config box to complete
2022-07-30 13:30:37.852   FindFriendsMini   Enter updated verification code in box and press submit.
2022-07-30 13:30:37.852   FindFriendsMini   ==================================================================================================================================
2022-07-30 13:30:37.852   FindFriendsMini   ==================================================================================================================================
2022-07-30 13:36:06.789   FindFriendsMini   Account requires verification within Plugin Config.


Found log I needed - although not debug logging think can still catch sequence, without overdoing it.

Try version:
1.3.9:
https://www.indigodomo.com/pluginstore/139/

Changes

Update to Python3 and update libraries
Add timesouts to Waze library, attempting to track down rare hang
Removing warning message regarding json parsing
More 2FA support/refactoring.
Add occupied TRUE/FALSE status to all Geofence devices - enabling them to be used as occupancy sensor within HomeKit using HomeKit plugin
Add Trigger/Event when 2FA fails.

Should trigger when happens, and then every few minutes there-after (!) until fixed.

Posted on
Fri Aug 26, 2022 7:52 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: 2FA Verification Code Trigger?

Thanks (again) for the nice update Glenn, works perfect!
Hope the new Trigger "Account needs re-verification" helps to eliminate the "dead" FFMini devices.
(But with Apple you never know.....)

Posted on
Wed Sep 07, 2022 6:48 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: 2FA Verification Code Trigger?

FindFriendsMini Plugin Version 1.3.9.

Hi Glenn,

Latest version works perfect but:
sometimes we get the error below in the log.
What's that?

All the best,

John


FindFriendsMini Error Caught Exception within Trigger Check
Traceback (most recent call last):
File "plugin.py", line 2437, in triggerCheck
if trigger.pluginProps["geofenceId"] != str(device.id) or (trigger.pluginTypeId == "geoFenceExit" and triggertype !='EXIT') or (trigger.pluginTypeId == "geoFenceEnter" and triggertype !='ENTER'):
KeyError: 'key geofenceId not found in dict'

Posted on
Wed Sep 07, 2022 3:19 pm
GlennNZ offline
User avatar
Posts: 1572
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: 2FA Verification Code Trigger?

McJohn wrote:
FindFriendsMini Plugin Version 1.3.9.

Hi Glenn,

Latest version works perfect but:
sometimes we get the error below in the log.
What's that?

All the best,

John


FindFriendsMini Error Caught Exception within Trigger Check
Traceback (most recent call last):
File "plugin.py", line 2437, in triggerCheck
if trigger.pluginProps["geofenceId"] != str(device.id) or (trigger.pluginTypeId == "geoFenceExit" and triggertype !='EXIT') or (trigger.pluginTypeId == "geoFenceEnter" and triggertype !='ENTER'):
KeyError: 'key geofenceId not found in dict'
Hi

I’ll have a look.

But would double check that trigger that has just run before error - has correctly selected geofence. If deleted or not selected may show something similar.

Glenn


Sent from my iPad using Tapatalk

Posted on
Thu Sep 08, 2022 2:48 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: 2FA Verification Code Trigger?

Thanks for the fast feedback.
Sorry, to say but can't find that Trigger. We have a lot of FindFriendsMini triggers and it's a pity that's it's not named into the log.

Strange thing is that all geofence Triggers are working normal.

John

Posted on
Thu Sep 08, 2022 2:51 am
GlennNZ offline
User avatar
Posts: 1572
Joined: Dec 07, 2014
Location: Central Coast, Australia

2FA Verification Code Trigger?

Ok.
It may relate to the 2FA re-verification required addition - I’ll make a small change and update next 24 hours or so. See if that fixes next time.
Done now: 1.3.10

https://github.com/Ghawken/IndigoPlugin ... e/Python_3

Glenn


Sent from my iPad using Tapatalk

Posted on
Fri Sep 09, 2022 2:16 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: 2FA Verification Code Trigger?

Thanks for the update Glenn.
Installed it yesterday and waited if the error came back.
(First people have to leave the building)
Sorry, to say, but it's still there. The only difference is that the Trigger suddenly now is named into the log, see below.
And there is nothing strange into this trigger;
(Trigger Device State Changed/Device FindFriendsJohn Labels Has Any change / No condition / Actions: Insert Device State into Variable/Device FindFriends John)


2022-09-09 08:30:12.461 Trigger FindFriendsJohnLabel
2022-09-09 08:30:14.537 FindFriendsMini Error Caught Exception within Trigger Check
Traceback (most recent call last):
File "plugin.py", line 2437, in triggerCheck
if trigger.pluginProps["geofenceId"] != str(device.id) or (trigger.pluginTypeId == "geoFenceExit" and triggertype !='EXIT') or (trigger.pluginTypeId == "geoFenceEnter" and triggertype !='ENTER'):
KeyError: 'key geofenceId not found in dict'

Posted on
Fri Sep 09, 2022 2:28 am
GlennNZ offline
User avatar
Posts: 1572
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: 2FA Verification Code Trigger?

Ok.

“Installed it yesterday” == this morning my time!

I’ll have another look - can you post the trigger info (copy python reference, and the in a scripting shell (bottom of plugin list) print the said reference ?). Welcome to PM it or post it.

Glenn


Sent from my iPad using Tapatalk

Posted on
Fri Sep 09, 2022 2:52 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: 2FA Verification Code Trigger?

You're fast again Glenn!

Do you mean this?

>>> indigo.triggers[86609135] # "FindFriendsJohnLabel"
<indigo.DeviceStateChangeTrigger object at 0x1095b31b0>
>>>

Posted on
Fri Sep 09, 2022 2:53 am
GlennNZ offline
User avatar
Posts: 1572
Joined: Dec 07, 2014
Location: Central Coast, Australia

2FA Verification Code Trigger?

No sorry. But close! Just but that line in a print() statement and try again
In that same shell:
Code: Select all
print(indigo.triggers[86609135])



Right click on the trigger causing error
Select Copy Python reference
Open a Scripting Shell - at bottom of Plugins List
In Scripting Shell type

print( **copy&paste here the copied reference then add closing bracket )

That result - so re-reading your example above.
Put the indigo.trigger in a print() bracket and post that output..

Thanks!


Sent from my iPad using Tapatalk

Posted on
Fri Sep 09, 2022 3:01 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: 2FA Verification Code Trigger?

Thanks for the fast course and your patience :wink:

(print(indigo.triggers[86609135])
configured : True
description :
deviceId : 741408810
enabled : True
folderId : 438434159
globalProps : MetaProps : (dict)
id : 86609135
name : FindFriendsJohnLabel
pluginProps : emptyDict : (dict)
remoteDisplay : True
sharedProps : com.indigodomo.indigoserver : (dict)
stateChangeType : Changes
stateSelector : labels
stateSelectorIndex : 0
stateValue :
suppressLogging : False
upload : True
>>>)

Who is online

Users browsing this forum: No registered users and 5 guests