Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Add option to automatically handle token #2

Merged
merged 3 commits into from
May 5, 2020

Conversation

gredin
Copy link
Contributor

@gredin gredin commented Apr 21, 2020

I'm using your work in my home project (controlling beer fermentation temperature). So, first: thanks!

I think clients of this library don't need to know the token acquisiton details.
This PR intends to hide these implementation details.

P.S. Also, getDeviceStatus method as a bonus.

@codetheweb
Copy link
Member

Thank you for your contributions!

I think we should keep the token methods public, as some applications may want to get/refresh the token according to their own logic - otherwise, this could be considered a breaking change.

@gredin
Copy link
Contributor Author

gredin commented Apr 22, 2020

I understand the breaking change issue.
What do you think about keeping the methods public, but adding an optional arg automaticToken* (default: false) in the constructor that would enable the automatic acquisition/refresh behaviour?

(*The naming needs improvement, but you get the idea.)

@codetheweb
Copy link
Member

I think that's a good idea, then we can check that property in the token methods and throw an error if it's true and the consumer is trying to call it anyways.

Maybe handleToken?

@gredin
Copy link
Contributor Author

gredin commented May 4, 2020

I'm back. What do you think about the changes?

Also, I fixed the choice of the sign method according to Tuya documentation:

TuyaCloud provide two sign algorithm based on different scenario:

- token related interface(v1.0/token&v1.0/token/{refresh_token}):sign = HMAC-SHA256(client_id + t, secret).toUpperCase()

- business interface(except token interfaces):sign = HMAC-SHA256(client_id + access_token + t, secret).toUpperCase()```

@codetheweb codetheweb changed the title first token acquisition is now implicitly handled Add option to automatically handle token May 5, 2020
@codetheweb
Copy link
Member

👌
Thanks for the contributions!

@codetheweb codetheweb merged commit c5e8206 into TuyaAPI:master May 5, 2020
@codetheweb
Copy link
Member

Published in v1.1.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants