Skip to content

Commit e5c84e5

Browse files
Add docs from gofiber/fiber@6d16bf5
1 parent fe3f005 commit e5c84e5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/core/middleware/basicauth.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ id: basicauth
66

77
Basic Authentication middleware for [Fiber](https://github.com/gofiber/fiber) that provides an HTTP basic authentication. It calls the next handler for valid credentials and [401 Unauthorized](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401) or a custom response for missing or invalid credentials.
88

9-
The default unauthorized response includes the header `WWW-Authenticate: Basic realm="Restricted"`.
9+
The default unauthorized response includes the header `WWW-Authenticate: Basic realm="Restricted", charset="UTF-8"` and sets `Cache-Control: no-store`.
1010

1111
## Signatures
1212

@@ -78,6 +78,8 @@ func handler(c fiber.Ctx) error {
7878
| Next | `func(fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
7979
| Users | `map[string]string` | Users defines the allowed credentials. | `map[string]string{}` |
8080
| Realm | `string` | Realm is a string to define the realm attribute of BasicAuth. The realm identifies the system to authenticate against and can be used by clients to save credentials. | `"Restricted"` |
81+
| Charset | `string` | Charset sent in the `WWW-Authenticate` header, so clients know how credentials are encoded. | `"UTF-8"` |
82+
| StorePassword | `bool` | Store the plaintext password in the context and retrieve it via `PasswordFromContext`. | `false` |
8183
| Authorizer | `func(string, string) bool` | Authorizer defines a function to check the credentials. It will be called with a username and password and is expected to return true or false to indicate approval. | `nil` |
8284
| Unauthorized | `fiber.Handler` | Unauthorized defines the response body for unauthorized responses. | `nil` |
8385

@@ -88,6 +90,8 @@ var ConfigDefault = Config{
8890
Next: nil,
8991
Users: map[string]string{},
9092
Realm: "Restricted",
93+
Charset: "UTF-8",
94+
StorePassword: false,
9195
Authorizer: nil,
9296
Unauthorized: nil,
9397
}

docs/core/whats_new.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ The adaptor middleware has been significantly optimized for performance and effi
975975

976976
### BasicAuth
977977

978-
The BasicAuth middleware was updated for improved robustness in parsing the Authorization header, with enhanced validation and whitespace handling. The default unauthorized response now uses a properly quoted and capitalized `WWW-Authenticate` header.
978+
The BasicAuth middleware now validates the `Authorization` header more rigorously and sets security-focused response headers. The default challenge includes the `charset="UTF-8"` parameter and disables caching. Passwords are no longer stored in the request context by default; use the new `StorePassword` option to retain them. A `Charset` option controls the value used in the challenge header.
979979

980980
### Cache
981981

0 commit comments

Comments
 (0)