Initial authorization enlighten
Hallo Daniel,
I made kind of same system for accessing enlighten api v4.
It is possible to renew the initial authorization of the app (get new acccess /refresh token). I contacted enlighten support about why this was needed: got no response. It is clear that enlighten api is developed for apps that regurly access enlighten api....
I made a selenium script to login into enlighten and permit app access and get new access token. I was not clever enough to do this in a straight forward way. Should however be possible with some authorization magic (cookies). I needed to add timestamp book keeping of access/refresh tokens to create new access token when refresh token is expired.
I doubt if my selenium method should be published. What is your opinion about trying to develop a script that uses user credentials to create new access token using some advanced authorization script?
Groeten, Ronald
Heya Ronald,
This token refresh has been one of the most annoying things about the new v4 API. My best guess is not being able to refresh an expired token is a limitation of the free Enlighten Watt plan, and that maybe the paid plans have a better way to achieve this? At least that seems to be the issue with the daily inverter telemetry data that rjjkm pointed out in Issue #4. So maybe it applies for this feature as well.
As far as having a way in python to refresh that, I'd love to have that. Unfortunately that may be a bit beyond my python expertise haha. The selenium script is a clever way to circumvent that issue, and I'm not sure how to apply that principle here to python ☹. But since my python script needs to run daily (because of the inverter telemetry free Watt plan limitation #4 ) I got around that by just making a new token every single day.
Hello,
I don't think you really need the refresh token. With some slight modifications, I can keep on using the api, without ever manually refreshing the token.
See https://github.com/bartverweire/py-shiny-enphase/blob/main/enlighten.py for the modifications.
- I have two methods : __get_access_token, and __refresh_access_token
- if the refresh fails, I can simply call __get_access_token, and that seems to work
- __assert_success now throws an exception if the response is not 200
- I keep track of the access token expiry date
I should probably create a pull request, but I'm not very familiar with that, sorry. Fyi. my project is about visualizing the telemetry information with a Shiny webpage, but it's not clearly documented yet. I hope to update that soon.
Regards,
Bart
Hmmm, that's very interesting. I'll take a peak at your changes when I have some time and see if I can integrate them in to this project.
Thanks!
Hallo Daniel and Bart,
I will have a look at this.
Some time ago, I wrote an API 4 interface to occasionally download data.
I needed the access token (of course) and the refresh token (the access token, expired after 24 hours). It happened that the refresh token expired as well after 7*24h.
For this I wrote a hack to get a new access and refresh token using Selenium (simulating a login with user credentials). I was not able to write a cleaner interface, due to lack of experience for this.
I contacted Enphase about their access/refresh method. Never got a sensible answer, other than pointing to the documentation.
My conclusion at that time was, that the access/refresh method works fine if you are more or less frequently (within 7*24h) access the API.
I can not imagine they changed this method.
BTW I stopped my project: I found pvoutput.org, I had build more or less the same functionality with python dash.. pvoutput.org is far better...
Groeten, Ronald
Op di 6 jun. 2023 14:35 schreef Daniel Patenaude @.***>:
Hmmm, that's very interesting. I'll take a peak at your changes when I have some time and see if I can integrate them in to this project.
Thanks!
— Reply to this email directly, view it on GitHub https://github.com/danielpatenaude/python_enlighten_api/issues/6#issuecomment-1578685918, or unsubscribe https://github.com/notifications/unsubscribe-auth/AODJDMGP47CANEZZU7DTKU3XJ4P2NANCNFSM6AAAAAAUY2JHPU . You are receiving this because you authored the thread.Message ID: @.***>