shiv3 / ocpp-cp-simulator

simple standalone ocpp charging port simulator written in reactjs, its based on OCPP 1.6J protocol
https://shiv3.github.io/ocpp-cp-simulator/
Apache License 2.0
4 stars 2 forks source link

Charge point basic authentication #7

Open philippbruhin opened 1 day ago

philippbruhin commented 1 day ago

Dear @shiv3, Thank you for sharing this valuable project with the community!

I noticed that it's possible to add the WebSocket URL under the settings. Is there a plan to support OCPP passwords as well? I couldn't find any implementation details regarding this in the ts-ocpp repository. However, OCPP defines basic authentication as option:

image Open Charge Point Protocol JSON 1.6, OCPP-J 1.6 Specification

shiv3 commented 16 hours ago

@philippbruhin Hi, thank you for finding this repository and giving feedback. I tried implementing Basic Auth settings in #8 , but I think there’s a high possibility that it won’t work. because this OCPP charger simulator is designed to run in the browser, but as mentioned in the StackOverflow post below, it seems difficult to attach Authorization headers to WebSocket requests from the browser. so please try connecting with the implementation in #8, and if it seems difficult to get it working, it might be better to choose a solution that works outside the browser. https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api

if you configure the setting like this, the websocket URL will be set look like this

image image
shiv3 commented 15 hours ago

this repository does not directly use the ts-ocpp ws implementation, but I think it will be usable if you use the setting that I added https://github.com/voltbras/ts-ocpp/pull/56

philippbruhin commented 11 hours ago

Hi @shiv3 ,

Thank you so much for implementing this feature! I really appreciate your effort. Unfortunately, as you anticipated, it didn't work on my end. Please see following screenshot for reference:

image

Thanks to the links you provided my summarized learnings are:

1. Browser Limitation: Browsers do not allow the wss://username:password@... format for WebSocket connections due to security concerns. Passing credentials in the URL is blocked by most modern browsers for security reasons, and WebSocket URLs don’t support this format.

2. OCPP Server Expectation (Header vs URL):

OCPP servers expect the Authorization header, not credentials embedded in the WebSocket URL. This is because:

I’ll look into a solution that works outside of the browser, for example https://github.com/matth-x/MicroOcppSimulator. Feel free to close this issue.

By the way, do you work a lot with OCPP? I’d love to stay in touch and exchange ideas, as I am working on similar projects. Is there any way to contact you?

Best regards, Philipp