-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Zaptec OAuth2 authentication for new format #25208
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
Conversation
- Replace PasswordCredentialsToken with custom exchangePasswordCredentials - Use grant_type=password with separate username, password, and scope parameters - Resolves 503 Service Unavailable errors after Zaptec API migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Instead of hardcoding the “offline_access” scope, make the scope value configurable so future API changes don’t require a code update.
- The custom token exchange duplicates HTTP client lookup logic; consider extracting that into a shared helper or leveraging the oauth2 library’s AuthStyle/Exchange directly.
- On non-200 responses you only return
resp.Status—consider reading and including the response body or adding retry logic for 503 errors to improve observability and resiliency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of hardcoding the “offline_access” scope, make the scope value configurable so future API changes don’t require a code update.
- The custom token exchange duplicates HTTP client lookup logic; consider extracting that into a shared helper or leveraging the oauth2 library’s AuthStyle/Exchange directly.
- On non-200 responses you only return `resp.Status`—consider reading and including the response body or adding retry logic for 503 errors to improve observability and resiliency.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Can you pls format your post? |
|
It's unlcear to me what this PR really does. According to Zaptec docs, username is required. |
yes sorry, I overlooked that the copy/paste from email and errors brought some html tags |
yes, understand it is confusing as the support answer refers to a password. In my first run I just implemented and directly what is asked here : https://docs.zaptec.com/docs/api-authentication Maybe not the best approach. Fortunately I found now a webarchive of the specification before the change. but I'm still not 100% sure to capture all the subtlety of the change. So I asked back the support. Will keep informed. apparently, the issue is popping up at other locations #25216 #25053 |
|
I have not yet received confirmation on the exact changes Zaptec made but I received this information We also have a rate limit of 1 request per minute in the Auth endpoint currently, until everything runs again smoothly on our side. So this could be the main issue you're facing. |
|
if anyone has more information please feel free to post it. On my side I did not yet get any clarification from Zaptec on the API change (if any). |
|
Could you test your changes individually? No username vs. changed scopes? Which one is really effective? Username is required according to Zaptec docs. OIDC is not. |
|
I tested both versions and both version worked. Having said that the original response from Zaptec support was in my view somehow misleading "Grant_Type was changed from password&username to password only". It requires clearly a username. And grant_type had, as far as I understand from webarchive, also before to be set to password. My first version was to implement the parameters straight according to the current example (replace oc.PasswordCredentialsToken with own method). I'm in touch with the support but I'm having a hard time to make them state clearly that nothing changed and that the issue is/was just Zaptec internal. If I get this confirmation we can cancel this change. Is someone still experiencing the issue after the restart of EVCC? |
If either works without the other, then non of the others is required, hence we don't need to change anything. |
Since last week I experienced issue with the Zaptec charger.
Logs were showing entries this
"ERROR 2025/11/09 23:47:21 charge power: Get "https://api.zaptec.com/api/chargers/caaexxxxxxxxxxxxxa57-a45f-19bdssssssss/state": oauth2: cannot fetch token: 503 Service Unavailable Response: 503 Service Temporarily Unavailable503 Service Temporarily Unavailable nginx/1.29.0"
I observed the same issue at several Zaptec installation with EVCC. I reached out to Zaptec support and they pointed to a change in the authentication format.
From Zaptec Support :
"On Monday, we migrated our authentication solution and the Grant_Type was changed from password&username to password only.
Could this be the cause of your error?
https://docs.zaptec.com/docs/api-authentication#/
curl --location 'https://api.zaptec.com/oauth/token'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'grant_type=password'
--data-urlencode 'username={[email protected]}'
--data-urlencode 'password={your_password}'
--data-urlencode 'scope=offline_access'
"
I made the change in the authentication format. It solved the issue at my installation and 2 others. No more authentication errors are thrown.