JasonGodmere / eapimt

Enphase API Management Tool
BSD 2-Clause "Simplified" License
2 stars 0 forks source link

authorize token -> access token -> refresh token according latest v4 api documentation #1

Open erdebe opened 2 years ago

erdebe commented 2 years ago

I am building an interface to the v4 api . I got stuck and found the eapimt sources. It is beautiful code for me as starting python programmer and I found the right direction. However I had to deviate at some points, looking at the latest documentation:

1 get the authorization code for a new partner (now not programmed), matching new_partner_token (I will try to implent this in my flow) 2 create encode secret from client_id and client_secret to be used in headers as 'Authorization': 'Basic '+encoded_secret ( encode_str = f'{client_id}:{client_secret}'.encode('ascii') encoded_secret = base64.b64encode(encode_str).decode('ascii') ) 2 use encoded_secret and authorization code to create initital access_token (valid 24 hours), a refresh token is generated as well (valid 7 days) 3 if access code is not valid, if refresh token is valid, create new access token (and refresh token) 4 if no valid access token could be created, repeat step 2

This mechanism is working for me, with keeping track of timestamps for expiration of access and refresh token. I am still improving my code.

I could not find the 3 step approach in the requestor code ( authorize -> access -> refresh) and the encoded secret.

Is the requestor code based on an older specification of the v4 api?

JasonGodmere commented 2 years ago

The code under basic usage in the README.md assumes you have a Partner plan to the Enphase API v4. From what I remember, the Enphase free plan has an additional step involving what they call "Home Owner Authentication" which my app can't help you with (see #6 of Quick Start https://developer-v4.enphase.com/docs/quickstart.html). You may be able to get similar authentication functionality as the Partner plan from a mid-tier plan, but I'm not sure. I would check with them.

In Summary: If you plan on continuing with the Free plan, my app may not be much help.

I'm actually surprised someone else found this application, I really just built it as a personal tool for a project I was working on. Let me know if you need more clarification.

erdebe commented 2 years ago

Hallo Jason,

Thanks for the quick answer.

I was already confused about the new_partner_token function ...

Indeed I use the free HO plan with the extra validation.

I am now busy with integrating my code with your code .Your code is a very good help to untangle my setup.

Your code will perfectly work, with adding management for initializing and refreshing the access token. Also the headers will use another authorization.

I try to be as clean as possible. Learning python on the go.

The one thing I have left open, is to get the HO validation automatic with username/password/client_id. I simply do not know enough about authentication... Could the authentication be done, similar to new_partner_token?

I have a special reason for my program. I have 2 Enphase systems (east,west) from different installers and want to be able to sum there numbers. Installers in the Netherlands won't install a second system according the prescribed Enphase method: there would be a physical link between the 2 systems, breaking my warranty they say. Enphase tells me this is not the case. Anyway PV installers are too busy selling new systems...

I managed already to achieve this, but my code is a mess...

I will add a simple gui. The code should also run on Android with pydroid3.

Groeten, Ronald

Op ma 27 jun. 2022 22:06 schreef Jason Godmere @.***>:

The code under basic usage in the README.md assumes you have a Partner plan to the Enphase API v4. From what I remember, the Enphase free plan has an additional step involving what they call "Home Owner Authentication" which my app can't help you with (see #6 of Quick Start https://developer-v4.enphase.com/docs/quickstart.html). You may be able to get similar authentication functionality as the Partner plan from a mid-tier plan, but I'm not sure. I would check with them.

In Summary: If you plan on continuing with the Free plan, my app may not be much help.

I'm actually surprised someone else found this application, I really just built it as a personal tool for a project I was working on. Let me know if you need more clarification.

— Reply to this email directly, view it on GitHub https://github.com/JasonGodmere/eapimt/issues/1#issuecomment-1167829460, or unsubscribe https://github.com/notifications/unsubscribe-auth/AODJDMH37G2GQY3VAVL6QTTVRICVTANCNFSM5Z53DNLA . You are receiving this because you authored the thread.Message ID: @.***>