|
ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
|
Layer: L6 Presentation ยท Build flags: PROTOCORE_ENABLE_AUTH (on by default)
The library protects a route with credentials via an auth-aware on() overload: you pass a realm, username, and password after the handler, and the handler runs only if the credentials check passes. Otherwise the server answers 401 with a WWW-Authenticate challenge automatically - you write no auth code.
Protecting one route. A public route uses the normal three-argument on(); a protected route adds the realm/user/password (digest defaults to false, i.e. Basic):
The handler body is reached only after a valid Authorization: Basic header.
Basic is base64, not encryption. The credentials are merely base64-encoded on the wire, so use Basic only over HTTPS or an SSH tunnel on untrusted networks. For a scheme where the password never crosses the wire, pass
digest=true- see DigestAuth.
PROTOCORE_ENABLE_AUTH is on by default; you only need to set it (to 0) to compile auth out.
The complete sketch (BasicAuth.ino), reproduced verbatim with added explanatory comments: