Skip to content

Conversation

tanordheim
Copy link
Contributor

Proposed changes

This makes the chargepoint ID used by the charger when authenticating part of the context the basic auth handler receives when authenticating the connection.

This is a breaking change, as it changes the basic auth handler signature. An option would be to introduce this as a separate type of basic auth handler, which I can change if you would prefer that path instead.

Types of changes

What types of changes does your code introduce?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of
them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before
merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

The use case for this builds on #346. If you using that PR have some custom chargepoint ID resolution set up, that might contain context necessary to authenticate the charger. A specific use-case I have for this is that the host the charger uses in the Host header is a significant part of the internal charge point ID; without that information in the basic auth handler I cannot authenticate the chargers.

@tanordheim tanordheim marked this pull request as ready for review March 12, 2025 09:26
@tanordheim tanordheim force-pushed the pass-chargepoint-id-to-basic-auth branch from 17cf26d to b10f3db Compare April 3, 2025 07:28
@tanordheim
Copy link
Contributor Author

@lorenzodonini I rebased this on master now after merging #346. You mentioned in #346 that maybe a context.Context would be a better option here than passing the chargepoint ID, should I rework this to support that instead or should we go with this for now?

@tanordheim tanordheim force-pushed the pass-chargepoint-id-to-basic-auth branch from b10f3db to f85c6c7 Compare August 15, 2025 08:27
@lorenzodonini
Copy link
Owner

@lorenzodonini I rebased this on master now after merging #346. You mentioned in #346 that maybe a context.Context would be a better option here than passing the chargepoint ID, should I rework this to support that instead or should we go with this for now?

I believe we could benefit converting all handlers to "proper middlewares" and rely on a context object being passed down. This allows applications to set whatever auth/meta info they need for the session setup, so they don't necessarily need to do multiple DB scans or use other hacks.

That being said, the change is out-of-scope and should be tackle separately.

s.server.SetBasicAuthHandler(func(username string, password string) bool {
validCredentials := authUsername == username && authPassword == password
s.server.SetBasicAuthHandler(func(chargePointID string, username string, password string) bool {
validCredentials := testPath == chargePointID && authUsername == username && authPassword == password
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing because the check should only be against testsws and not the full testPath. Would merge once this is fixed.

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

Successfully merging this pull request may close these issues.

2 participants