You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/middleware/basicauth.md
+1-13Lines changed: 1 addition & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,13 @@ id: basicauth
6
6
7
7
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.
8
8
9
-
The default unauthorized response includes the header `WWW-Authenticate: Basic realm="Restricted", charset="UTF-8"` and sets `Cache-Control: no-store`.
9
+
The default unauthorized response includes the header `WWW-Authenticate: Basic realm="Restricted", charset="UTF-8"`, sets `Cache-Control: no-store`, and adds a `Vary: Authorization` header.
10
10
11
11
## Signatures
12
12
13
13
```go
14
14
funcNew(configConfig) fiber.Handler
15
15
func UsernameFromContext(c fiber.Ctx) string
16
-
func PasswordFromContext(c fiber.Ctx) string
17
16
```
18
17
19
18
## Examples
@@ -72,15 +71,6 @@ hashing algorithm from a prefix:
72
71
If no prefix is present the value is interpreted as a SHA-256 digest encoded in
| 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"`|
91
81
| Charset |`string`| Charset sent in the `WWW-Authenticate` header, so clients know how credentials are encoded. |`"UTF-8"`|
92
82
| HeaderLimit |`int`| Maximum allowed length of the `Authorization` header. Requests exceeding this limit are rejected. |`8192`|
93
-
| StorePassword |`bool`| Store the plaintext password in the context and retrieve it via `PasswordFromContext`. |`false`|
94
83
| Authorizer |`func(string, string, fiber.Ctx) bool`| Authorizer defines a function to check the credentials. It will be called with a username, password, and the current context and is expected to return true or false to indicate approval. |`nil`|
95
84
| Unauthorized |`fiber.Handler`| Unauthorized defines the response body for unauthorized responses. |`nil`|
Copy file name to clipboardExpand all lines: docs/whats_new.md
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1019,7 +1019,6 @@ Examples include:
1019
1019
-`csrf.HandlerFromContext(c)`
1020
1020
-`session.FromContext(c)`
1021
1021
-`basicauth.UsernameFromContext(c)`
1022
-
-`basicauth.PasswordFromContext(c)`
1023
1022
-`keyauth.TokenFromContext(c)`
1024
1023
1025
1024
When used with the Logger middleware, the recommended approach is to use the `CustomTags` feature of the logger, which allows you to call these specific `FromContext` functions. See the [Logger](#logger) section for more details.
@@ -1054,7 +1053,7 @@ The adaptor middleware has been significantly optimized for performance and effi
1054
1053
1055
1054
### BasicAuth
1056
1055
1057
-
The BasicAuth middleware now validates the `Authorization` header more rigorously and sets security-focused response headers. Passwords must be provided in **hashed** form (e.g. SHA-256 or bcrypt) rather than plaintext. 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.
1056
+
The BasicAuth middleware now validates the `Authorization` header more rigorously and sets security-focused response headers. Passwords must be provided in **hashed** form (e.g. SHA-256 or bcrypt) rather than plaintext. The default challenge includes the `charset="UTF-8"` parameter and disables caching. Responses also set a `Vary: Authorization` header to prevent caching based on credentials. Passwords are no longer stored in the request context. A `Charset` option controls the value used in the challenge header.
1058
1057
A new `HeaderLimit` option restricts the maximum length of the `Authorization` header (default: `8192` bytes).
1059
1058
The `Authorizer` function now receives the current `fiber.Ctx` as a third argument, allowing credential checks to incorporate request context.
1060
1059
@@ -1916,7 +1915,6 @@ You must update your code to use the dedicated exported functions provided by ea
Passwords configured for BasicAuth must now be pre-hashed. If no prefix is supplied the middleware expects a SHA-256 digest encoded in hex. Common prefixes like `{SHA256}` and `{SHA512}` and bcrypt strings are also supported. Plaintext passwords are no longer accepted.
1948
+
Passwords configured for BasicAuth must now be pre-hashed. If no prefix is supplied the middleware expects a SHA-256 digest encoded in hex. Common prefixes like `{SHA256}` and `{SHA512}` and bcrypt strings are also supported. Plaintext passwords are no longer accepted. Unauthorized responses also include a `Vary: Authorization` header for correct caching behavior.
1951
1949
1952
-
You can also set the optional `HeaderLimit`, `StorePassword`, and `Charset`
1950
+
You can also set the optional `HeaderLimit` and `Charset`
1953
1951
options to further control authentication behavior.
0 commit comments