Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WYZE Refresh Tokens #258

Open
mikl730 opened this issue Jul 14, 2024 · 8 comments
Open

WYZE Refresh Tokens #258

mikl730 opened this issue Jul 14, 2024 · 8 comments
Labels
bug Something isn't working question Further information is requested

Comments

@mikl730
Copy link

mikl730 commented Jul 14, 2024

Refresh tokens fail to be accepted by wyze servers after about 1-hour and 45 minutes. See the discussion in attached projects/forum for more details.

SecKatie/ha-wyzeapi#612
https://forums.wyze.com/t/refresh-tokens-not-working/303714/2

Just posting to prevent anyone from wasting hours like I did trying to fix this issue.

@mikl730 mikl730 added bug Something isn't working question Further information is requested labels Jul 14, 2024
Copy link

Message that will be displayed on users' first issue

@mikl730
Copy link
Author

mikl730 commented Jul 15, 2024

I spent the evening hack together a fix. First let me say I have never worked in this language before and I'm a network engineer that normally Purposely stays away from code but I want my freaking automations to work at home so I sucked it up lol.

Here's what changes I made to index.js in /var/lib/homebridge/node_modules/homebridge-wyze-smart-home/node_modules/wyze-api/src
Added a variable at the top

this.failure = "";

Changed refresh interval to 60 minutes because wyze is expiring them in 1.5 hours right now

setInterval(this.refreshToken.bind(this), 3600);

Edited the 2001 test to add it setting that var

 if   (code === 2001 ||
        errorMessage.toLowerCase().includes("accesstokenerror") ||
        errorMessage.toLowerCase().includes("access token is error")
      	)
 	{
        this.access_token = "";
        await this.refreshToken().catch((err) => {
        this.failure = "true";
        });

Added another if check below for the var then deleted the token file

	 if (this.failure = true)	
 	{
    	const tokenPath = this._tokenPersistPath();       	
	fs.unlink(tokenPath);
	throw new Error(`Oh no 2002 failure refresh token is bad. Erased the stupid file`);
	this.failure = false;
        };

@dlewanda
Copy link

@mikl730 Thanks for posting your hack. I am a software developer by trade but haven't done Javascript or Node.js in many years. I am seeing the same issue as you. If you can confirm your fix is continuing to work long term, I'm happy to figure out how to get a PR together that captures your fix to be merged into a release of this repo. I've been a long-time user and would like to give back, and I also really want to get my setup working.

@mikl730
Copy link
Author

mikl730 commented Jul 20, 2024 via email

@hartyparty
Copy link

I spent the evening hack together a fix. First let me say I have never worked in this language before and I'm a network engineer that normally Purposely stays away from code but I want my freaking automations to work at home so I sucked it up lol.

Here's what changes I made to index.js in /var/lib/homebridge/node_modules/homebridge-wyze-smart-home/node_modules/wyze-api/src Added a variable at the top

this.failure = "";

Changed refresh interval to 60 minutes because wyze is expiring them in 1.5 hours right now

setInterval(this.refreshToken.bind(this), 3600);

Edited the 2001 test to add it setting that var

 if   (code === 2001 ||
        errorMessage.toLowerCase().includes("accesstokenerror") ||
        errorMessage.toLowerCase().includes("access token is error")
      	)
 	{
        this.access_token = "";
        await this.refreshToken().catch((err) => {
        this.failure = "true";
        });

Added another if check below for the var then deleted the token file

	 if (this.failure = true)	
 	{
    	const tokenPath = this._tokenPersistPath();       	
	fs.unlink(tokenPath);
	throw new Error(`Oh no 2002 failure refresh token is bad. Erased the stupid file`);
	this.failure = false;
        };

can you attach a copy of the index.js? I tried to make these changes but get completely yelled at by HomeBridge about this plugin.

@AlienInCA
Copy link

Posting here hoping that a solution is available soon.

@tbsaunders1
Copy link

i'm having the same issue here, have changed access token and key with same error persisting.

homebridge v1.7.0
node v20.16.0
wyze plugin v0.5.46

[Wyze] Wyze API Error (2001): 'access token is error'
[Wyze] Wyze API Error (1001): 'INVALID_PARAMETER'

@jfarmer08
Copy link
Owner

@hartyparty if you feel your fix will work for other, please feel free to create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants