Authentication
Restrict access to the WebSerial terminal with HTTP Basic Authentication using a username and password.
WebSerial supports HTTP Basic Authentication. Enable it to ensure that only authorized users can view the logs of your device and send commands to it.
Enable authentication
Call setAuthentication() with a username and password:
WebSerial.setAuthentication("username", "password");Prop
Type
When authentication is enabled, WebSerial requires the credentials both for the terminal page and for the WebSocket connection that carries the log output.
Example
#include <WebSerial.h>
// ...
void setup() {
// ...
WebSerial.begin(&server);
// Require credentials to access the terminal
WebSerial.setAuthentication("myUsername", "myPassword");
server.begin();
}
void loop() {
// ...
WebSerial.loop();
}Notes
- Authentication is enabled only when both the username and the password are non-empty. Pass empty strings to disable it.
setAuthentication()can be called before or afterbegin().- HTTP Basic Authentication does not encrypt traffic. Use strong, unique credentials for each device and do not reuse default or easily guessable credentials.