hepcat72 / node-red-contrib-life360

GNU General Public License v3.0
3 stars 4 forks source link

Life360 Server Not Receiving Updates Since Saturday #16

Closed ctreischman closed 1 year ago

ctreischman commented 1 year ago

Saturday evening I was getting this: [Life360 server error logging in: 403 Error: Request failed with status code 403] Yesterday I got this in the event log: 301 moved permanently.

I normally have node-red on linux, but I just now tried it with a new install on windows and received the same result.

Is anyone else experiencing this?

ctreischman commented 1 year ago

Windows Powershell is receiving this on repeat:

Unhandled rejection Error: Unauthorized at C:\Users\ctrei.node-red\node_modules\node-red-contrib-life360\index.js:52:16 at tryCatcher (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\promise.js:547:31) at Promise._settlePromise (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\promise.js:604:18) at Promise._settlePromise0 (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\promise.js:649:10) at Promise._settlePromises (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\promise.js:725:18) at _drainQueueStep (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\async.js:93:12) at _drainQueue (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\async.js:86:9) at Async._drainQueues (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\async.js:102:5) at Async.drainQueues [as _onImmediate] (C:\Users\ctrei.node-red\node_modules\bluebird\js\release\async.js:15:14) at process.processImmediate (node:internal/timers:476:21)

hepcat72 commented 1 year ago

Seems you're right. Thanks for the thorough report. The last Life360 event I have gotten was on 7/28/2023 at 10:26pm EST. I don't appear to have the 301 error. It looks like the 403 errors started for me on 29 Jul 17:31:53. Before that, I had login errors starting at around 15 Jul 17:58:11.

I don't have time to look into it ATM, but I definitely want to address it soon.

ctreischman commented 1 year ago

Excellent. Thanks for your response. When it stopped working then I started tinkering. I hope I haven't changed anything too important on my end while trying to "fix" it.

hepcat72 commented 1 year ago

OK. Did some quick searching and it appears that other repos like mine have already found and fixed the issue. These are the changes that are necessary. Simple enough. Just need to find the time to do it.

ctreischman commented 1 year ago

Great news! I appreciate you finding the time to research.

hepcat72 commented 1 year ago

Well, I made what I thought were equivalent edits in index.js to the token retrieval code, but I'm still getting the same error. What's weird is, using curl I can just update the api URL (leaving the secret and headers the same, and it works. I'm not really great at server api stuff.

@brianmay - would you be willing to take a look at this?

hepcat72 commented 1 year ago

Like, if I do:

curl -s -X POST -H "Authorization: Basic cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg==" -F "grant_type=password" -F "username=MY_EMAIL_ADDRESS" -F "password=MY_PASSWORD" https://api-cloudfront.life360.com/v3/oauth2/token.json

...it gives me a token, but through the javascript code, it still gives me 403.

ctreischman commented 1 year ago

I see the same thing. Unfortunately, I am no help with javascript.

On Tue, Aug 1, 2023 at 10:23 PM Robert Leach @.***> wrote:

Like, if I do:

curl -s -X POST -H "Authorization: Basic cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg==" -F "grant_type=password" -F "username=MY_EMAIL_ADDRESS" -F "password=MY_PASSWORD" https://api-cloudfront.life360.com/v3/oauth2/token.json

...it gives me a token, but through the javascript code, it still gives me 403.

— Reply to this email directly, view it on GitHub https://github.com/hepcat72/node-red-contrib-life360/issues/16#issuecomment-1661431221, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASQVTLY73NKLQUIVQL4FSYLXTHB4DANCNFSM6AAAAAA26THW3E . You are receiving this because you authored the thread.Message ID: @.***>

hepcat72 commented 1 year ago

Oh God. I forgot I changed my password recently. Sigh... I've gotta run now, but maybe I can fix this later today.

hepcat72 commented 1 year ago

Yep, OK. I have mine working now. Changing the secret and adding user agent (as in the other PR), seem unnecessary. I'll let it run today and see if I find out if those changes become necessary.

ctreischman commented 1 year ago

Excellent. I appreciate your time and efforts. I will probably need a little instruction on how to implement your changes once you are finished.

Thank you.

On Wed, Aug 2, 2023 at 8:10 AM Robert Leach @.***> wrote:

Yep, OK. I have mine working now. Changing the secret and adding user agent (as in the other PR), seem unnecessary. I'll let it run today and see if I find out if those changes become necessary.

— Reply to this email directly, view it on GitHub https://github.com/hepcat72/node-red-contrib-life360/issues/16#issuecomment-1662186282, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASQVTL4A4KAKMP2HZPYYXGLXTJGUXANCNFSM6AAAAAA26THW3E . You are receiving this because you authored the thread.Message ID: @.***>

hepcat72 commented 1 year ago

Until I create a new release, you can just open ~/.node-red/node_modules/node-red-contrib-life360/index.js (or similar - I typed this by memory) and manually edit it to change api.life360.com to api-cloudfront.life360.com. Then restart node-red. I'd have solved it last night if I'd realized I needed to update my password in the server config node.

ctreischman commented 1 year ago

Thanks. I'll give it a try.

⁣Chris​

On Aug 2, 2023, 9:09 AM, at 9:09 AM, Robert Leach @.***> wrote:

Until I create a new release, you can just open ~/.node-red/node_modules/node-red-contrib-life360/index.js (or similar - I typed this by memory) and manually edit it to change api.life360.com to api-cloudfront.life360.com. Then restart node-red. I'd have solved it last night if I'd realized I needed to update my password in the server config node.

-- Reply to this email directly or view it on GitHub: https://github.com/hepcat72/node-red-contrib-life360/issues/16#issuecomment-1662282924 You are receiving this because you authored the thread.

Message ID: @.***>

Pablo-Ortiz-Lopez commented 1 year ago

Hello, I have just started using this integration a few minutes ago and I had this same issue. I have found that doing what @hepcat72 suggested in the last message isn't enough to fix the issue, but adding the 'user-agent': 'com.life360.android.safetymapd' header to all requests, along with the URL change, does fix the issue.

hepcat72 commented 1 year ago

Thanks @Pablo-Ortiz-Lopez. That's interesting. I wonder why it works for me without specifying the user agent... Would you mind removing it and changing the following:

    if (error.response) {
        // The request was made and the server responded with a status code
        // that falls out of the range of 2xx
        throw new Error(`${errorPrefix}: ${error.response.status} ${error.toString()}`)

to:

    if (error.response) {
        // The request was made and the server responded with a status code
        // that falls out of the range of 2xx
        throw new Error(`${errorPrefix}: ${error.response.status} ${error.toString()} ${error.response.data.errorMessage}`)

Restart node-red and paste the error from the STDOUT node red log into a comment here?

I would like to supply a user agent string that represents the package instead of using the android user agent, but I want to be able to tell whether any error I might get is the same or different than yours...

The only thing I can guess is that in my current version of node-red, it is automatically extracting user agent from either my web browser or the html form presented in the server node's config. I did notice that the request recorded in the response object that axios created DID have a user-agent value, hence my suspicion of what's going on. And my value was different than the one in the other PR.

And can you tell me what version of node-red you're running?

hepcat72 commented 1 year ago

I'm not going to have time to do this this evening. I'm teaching 2 classes and won't be home until 10 or so. If anyone has nothing else to do this evening and has it working based on the suggestions above, maybe clone the repo, create a branch, put in your changes, commit and push, then create a PR?

Otherwise, it will probably be tomorrow evening before I get to it.

ctreischman commented 1 year ago

Your first suggestion has worked for me so I'm not rushing you.

⁣Chris​

On Aug 2, 2023, 5:22 PM, at 5:22 PM, Robert Leach @.***> wrote:

I'm not going to have time to do this this evening. I'm teaching 2 classes and won't be home until 10 or so. If anyone has nothing else to do this evening and has it working based on the suggestions above, maybe clone the repo, create a branch, put in your changes, commit and push, then create a PR?

Otherwise, it will probably be tomorrow evening before I get to it.

-- Reply to this email directly or view it on GitHub: https://github.com/hepcat72/node-red-contrib-life360/issues/16#issuecomment-1663049801 You are receiving this because you authored the thread.

Message ID: @.***>

RoadrunnerJDD commented 1 year ago

I just tried to install this yesterday so it has never worked for me so I may have something configured wrong. I changed the api.life360.com to api-cloudfront.life360.com but it is still not working. I mainly have industrial automation and micro controller programming knowledge but can send you what ever you need if you tell me where to find it. I am running node red v1.2.2 in a docker on an old OLD laptop running Zorin Linux. To confirm the user name is my email address? What file has the error if statement that needs to be change?

RoadrunnerJDD commented 1 year ago

This is the error message I am getting in the terminal:

Unhandled rejection Error: Unauthorized at request.then.catch.err (/data/node_modules/node-red-contrib-life360/index.js:52:16) at tryCatcher (/data/node_modules/bluebird/js/release/util.js:16:23) at Promise._settlePromiseFromHandler (/data/node_modules/bluebird/js/release/promise.js:547:31) at Promise._settlePromise (/data/node_modules/bluebird/js/release/promise.js:604:18) at Promise._settlePromise0 (/data/node_modules/bluebird/js/release/promise.js:649:10) at Promise._settlePromises (/data/node_modules/bluebird/js/release/promise.js:725:18) at _drainQueueStep (/data/node_modules/bluebird/js/release/async.js:93:12) at _drainQueue (/data/node_modules/bluebird/js/release/async.js:86:9) at Async._drainQueues (/data/node_modules/bluebird/js/release/async.js:102:5) at Immediate.Async.drainQueues [as _onImmediate] (/data/node_modules/bluebird/js/release/async.js:15:14) at runCallback (timers.js:705:18) at tryOnImmediate (timers.js:676:5) at processImmediate (timers.js:658:5)

RoadrunnerJDD commented 1 year ago

I found why I could not find the error if statement. I downloaded this from the palette installer in node-red and it does not have that statement in it. Looking at file in the github repository I found it right were I expected it. Should I replace my index.js file with the one from github?

hepcat72 commented 1 year ago

Hi @RoadrunnerJDD. Welcome. I'm not home yet, but if the "if statement" is t there, my guess would be that maybe you don't have the latest version installed?

That node_modules path you posted isn't where I would expect it to be. I'm not certain where the node-red version you have installs itself, but mine put it under ~/.node-red/node_modules. Maybe you also tried installing from the command line?

The username is the email address for your Life360 account.

And the error you posted also seems to possibly be associated with an old version that was not properly handling exceptions.

RoadrunnerJDD commented 1 year ago

OK. I will copy the github version over to it. That one is from the node-red palette manager.

hepcat72 commented 1 year ago

Hmm. You shouldn't have to do that. The version you get from the palette manager should be the same, so I'm not sure what's going on there. The next time you update from the palette manager, it will overwrite it. Did you look in the manager to see what version it installed and if it says there's an update available?

RoadrunnerJDD commented 1 year ago

That was a fresh install as of 2 days ago. I can get that info this evening when I get back home. I had some issues copying it straight from the gethub repository last night getting node-red to recognize it and had to give up for the night. Will work on it again when I get home.

hepcat72 commented 1 year ago

I suspect there may be issues with your node red install. I wouldn't advise copying files into a palette-installed module. I just vpn'd into my home network so that I can show you some screenshots.

This is what the life360 install in the palatte manager should look like (barring NR version differences):

Screen Shot 2023-08-03 at 10 52 37 AM

If there is an update available, you will have an update button in the lower righthand corner, like this one:

Node-RED raspberrypi localdomain - Screen Shot 2023-08-03 at 10 53 05 AM

You should be able to confirm that the version shown in the palette manager matches the version in the package.json file in the location where you found the package. For example, this shows I have the latest version (1.1.0):

raspberrypi[2023-08-03 10:55:41]:~>cd .node-red/node_modules/node-red-contrib-life360/
raspberrypi[2023-08-03 10:56:06]:...ed/node_modules/node-red-contrib-life360>ls
icons/  index.js*  LICENSE  life360.html  life360.js  node_modules/  nodes/  package.json  README.md  static/
raspberrypi[2023-08-03 10:56:13]:...ed/node_modules/node-red-contrib-life360>tail package.json 
      "api": "life360.js"
    }
  },
  "homepage": "https://github.com/hepcat72/node-red-contrib-life360",
  "repository": {
    "type": "git",
    "url": "git://github.com/hepcat72/node-red-contrib-life360.git"
  },
  "version": "1.1.0"
}

If all that checks out, then you can double-check your settings.js file to confirm the node_modules location:

    // By default, all user data is stored in a directory called `.node-red` under
    // the user's home directory. To use a different location, the following
    // property can be used
    //userDir: '/home/nol/.node-red/',

...again, barring version differences.

RoadrunnerJDD commented 1 year ago

OK. Thanks. Sadly I do not have a vpn set up so I will have to wait till I get home after work to look at this.

hepcat72 commented 1 year ago

That was a fresh install as of 2 days ago. I can get that info this evening when I get back home. I had some issues copying it straight from the gethub repository last night getting node-red to recognize it and had to give up for the night. Will work on it again when I get home.

Well, I figured out why you had an old version of the life360 node. When I created the first release, I'd been given the impression that publishing new versions to npm would automatically be detected by node-red and show up in the palette manager. Apparently that wasn't happening. But the palette manager now shows the latest version with the fixes for this issue.

@Pablo-Ortiz-Lopez - I only added the user agent to the token request, but there's no way for me to test that this is sufficient. Can you confirm whether or not you need the user agent in every call? If it works for you, I will close this issue.

Pablo-Ortiz-Lopez commented 1 year ago

@Pablo-Ortiz-Lopez - I only added the user agent to the token request, but there's no way for me to test that this is sufficient. Can you confirm whether or not you need the user agent in every call? If it works for you, I will close this issue.

I have tried without the user-agent, and it is now working, which is strange. I guess it might not have worked at first when i modified the node_modules file due to cache or something like that

hepcat72 commented 1 year ago

OK. NR definitely has to be restarted. If you did that, then perhaps it was a fluke:

image

Regardless, it doesn't hurt to have a user agent. I'm going to close this as resolved.

RoadrunnerJDD commented 1 year ago

That seems to have done it. I reinstalled and now it shows V1.1.1 were before I am pretty sure it said v1.0. Server logged in and pulled the circles, people, and places just fine. I haven't had anyone leave or come back yet to trigger an event yet though. Thanks allot for your help and for the add in to begin with.