Skip to content

simpleAPI HTTP Zugangsdaten übergeben#3339

Open
kevinwieland wants to merge 1 commit intomasterfrom
http-simpleAPI-authentication
Open

simpleAPI HTTP Zugangsdaten übergeben#3339
kevinwieland wants to merge 1 commit intomasterfrom
http-simpleAPI-authentication

Conversation

@kevinwieland
Copy link
Copy Markdown
Contributor

Ermöglicht es bei Nutzung der HTTP Variante der simpleAPI optional Zugangsdaten zu übergeben wenn die Benutzerverwaltung genutzt wird.

In diesem Zuge greift die simpleAPI nicht mehr auf den internen Port sondern den von extern erreichbaren zu.

Eine Anonyme Anmeldung ohne Benutzerverwaltung ist nach wie vor möglich.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the PHP simpleAPI so HTTP callers can optionally pass MQTT credentials, and it switches the API toward using the externally reachable MQTT endpoint instead of the internal one.

Changes:

  • Added MQTT credential injection/testing paths in MqttClient and Authenticator.
  • Wired request-supplied username/password into simpleapi.php and added read-response debug info.
  • Changed default configuration to use MQTT port 8883 and enabled authentication by default.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
simpleAPI/src/MqttClient.php Adds runtime MQTT credential overrides and broker credential testing helpers.
simpleAPI/src/Authenticator.php Expands authentication to validate against MQTT credentials and anonymous-broker access.
simpleAPI/simpleapi.php Passes request credentials into the MQTT client and threads debug info into read responses.
simpleAPI/config/config.php Changes default MQTT port and auth defaults for the simpleAPI configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to +48
// Fallback: Prüfen ob MQTT Broker ohne Authentifizierung zugänglich ist
if ($this->checkMqttNoAuth()) {
return true;
}

Comment on lines +154 to +156
// Wenn keine lokalen Benutzer definiert sind oder MqttClient verfügbar ist:
// Anmeldedaten gegen MQTT Broker testen
if ($this->mqttClient && (empty($users) || !isset($users[$username]))) {
Comment thread simpleAPI/simpleapi.php
Comment on lines +79 to +89
// MQTT-Anmeldedaten aus Parametern übernehmen falls vorhanden
if (isset($params['username']) && isset($params['password'])) {
$this->mqttClient->setCredentials($params['username'], $params['password']);

if ($this->config['debug']) {
$debugInfo[] = "Using MQTT credentials from parameters: username={$params['username']}";
}
} else {
// Keine Parameter-Anmeldedaten vorhanden
if ($this->config['debug']) {
$debugInfo[] = "No credentials provided via parameters, using config or anonymous access";
Comment thread simpleAPI/simpleapi.php
Comment on lines +367 to +370
// Debug-Informationen hinzufügen wenn vorhanden
if (!empty($debugInfo) && $this->config['debug']) {
$result['debug_info'] = $debugInfo;
}
'mqtt' => [
'server' => 'localhost',
'port' => 1884,
'port' => 8883,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@benderl ist es nicht so das 8883 immer verfügbar ist? 1883 geht aufjedenfall nicht, da bei aktiver BV deaktiviert.

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