Authentication
Protect the ElegantOTA portal and update endpoints with HTTP Basic Authentication using a username and password.
ElegantOTA supports HTTP Basic Authentication. When it is enabled, the browser asks for a username and password before it opens the portal, and the device rejects update requests without valid credentials. This prevents unauthorized users from installing firmware on your device.
Enable authentication
Call setAuth() with a username and a password:
ElegantOTA.setAuth("username", "password");Prop
Type
Alternatively, pass the credentials to begin():
ElegantOTA.begin(&server, "username", "password");Authentication is enabled only when both the username and the password are non-empty.
Example
#include <ElegantOTA.h>
// ... web server declaration
void setup() {
// ... connect to Wi-Fi
ElegantOTA.begin(&server);
ElegantOTA.setAuth("myUsername", "myPassword");
server.begin();
}
void loop() {
server.handleClient();
ElegantOTA.loop();
}Clear authentication
To disable authentication after it was set, call clearAuth():
ElegantOTA.clearAuth();Protected endpoints
When authentication is enabled, the following routes require credentials:
| Route | Edition |
|---|---|
/update (portal) | Lite and Pro |
/ota/start, /ota/upload | Lite and Pro |
/ota/download, /ota/check, /ota/install, /ota/status | Pro |
The /ota/metadata route, which the portal uses to display device information, is served without authentication. It reports the chip family, the partition sizes and the size of the running firmware. In ElegantOTA Pro, it also reports the portal title, the hardware ID, the firmware version, the enabled modes and the update channel URL. The Pro logo routes (/ota/logo/light and /ota/logo/dark) are also public.
Use cases
- Security: prevent unauthorized firmware or filesystem updates.
- Access control: assign unique credentials to each device so that only authorized personnel or systems can update it.
- Compliance: meet security standards that require authentication for device management interfaces.
Best practices
- Use strong, unique credentials for each device. Do not use default or easily guessed credentials.
- Store credentials securely and avoid hard-coding them in source code that is shared or published.
- Rotate credentials regularly.
- Test the configuration to confirm that the portal rejects requests without valid credentials.
- HTTP Basic Authentication sends credentials encoded, not encrypted. Use it on networks you trust.
Auto UpdateNewPro
Configure an update channel so the device checks a JSON manifest on a schedule and installs newer firmware. Covers the manifest, version comparison and onUpdateAvailable.
Disable Firmware OTAPro
Enable or disable firmware updates at runtime in ElegantOTA Pro, and check whether the firmware update target is enabled.