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
| Next |`func(fiber.Ctx) bool`| A function to skip this middleware when returned true. |`nil`|
69
69
| Except |`[]string`| Array of cookie keys that should not be encrypted. |`[]`|
70
-
| Key |`string`| A base64-encoded unique key to encode & decode cookies. Required. Key length should be 32 characters. | (No default, required field) |
70
+
| Key |`string`| A base64-encoded unique key to encode & decode cookies. Required. Key length should be 16, 24, or 32 bytes. | (No default, required field) |
71
71
| Encryptor |`func(decryptedString, key string) (string, error)`| A custom function to encrypt cookies. |`EncryptCookie`|
72
72
| Decryptor |`func(encryptedString, key string) (string, error)`| A custom function to decrypt cookies. |`DecryptCookie`|
# Incorrect API key -> 401 Invalid or expired API Key
69
75
curl --cookie "access_token=Clearly A Wrong Key" http://localhost:3000
70
-
#> missing or malformed API Key
76
+
#> Invalid or expired API Key
71
77
```
72
78
73
79
For a more detailed example, see also the [`github.com/gofiber/recipes`](https://github.com/gofiber/recipes) repository and specifically the `fiber-envoy-extauthz` repository and the [`keyauth example`](https://github.com/gofiber/recipes/blob/master/fiber-envoy-extauthz/authz/main.go) code.
74
80
75
81
### Authenticate only certain endpoints
76
82
77
-
If you want to authenticate only certain endpoints, you can use the `Config` of keyauth and apply a filter function (eg. `authFilter`) like so
83
+
If you want to authenticate only certain endpoints, you can use the `Next` function in the config to skip the middleware for specific routes.
| Next |`func(fiber.Ctx) bool`| Next defines a function to skip this middleware when returned true. |`nil`|
219
-
| SuccessHandler |`fiber.Handler`| SuccessHandler defines a function which is executed for a valid key. |`nil`|
220
-
| ErrorHandler |`fiber.ErrorHandler`| ErrorHandler defines a function which is executed for an invalid key. By default a 401 response with a `WWW-Authenticate` challenge is sent. |`nil`|
221
-
| KeyLookup |`string`| KeyLookup is a string in the form of "`<source>:<name>`" that is used to extract the key from the request. | "header:Authorization" |
222
-
| CustomKeyLookup |`KeyLookupFunc` aka `func(c fiber.Ctx) (string, error)`| If more complex logic is required to extract the key from the request, an arbitrary function to extract it can be specified here. Utility helper functions are described below. |`nil`|
223
-
| AuthScheme |`string`| AuthScheme to be used with the `Authorization` header. When `KeyLookup` is not set, this defaults to `"Bearer"`. | "Bearer" |
261
+
| SuccessHandler |`fiber.Handler`| SuccessHandler defines a function which is executed for a valid key. |`c.Next()`|
262
+
| ErrorHandler |`fiber.ErrorHandler`| ErrorHandler defines a function which is executed for an invalid key. By default a 401 response with a `WWW-Authenticate` challenge is sent. | Default error handler |
263
+
| Validator |`func(fiber.Ctx, string) (bool, error)`|**Required.** Validator is a function to validate the key. |`nil` (panic) |
264
+
| Extractor |`keyauth.Extractor`| Extractor defines how to retrieve the key from the request. Use helper functions like `keyauth.FromAuthHeader` or `keyauth.FromCookie`. |`keyauth.FromAuthHeader("Authorization", "Bearer")`|
224
265
| Realm |`string`| Realm specifies the protected area name used in the `WWW-Authenticate` header. |`"Restricted"`|
225
-
| Validator |`func(fiber.Ctx, string) (bool, error)`| Validator is a function to validate the key. | A function for key validation |
Two public utility functions are provided that may be useful when creating custom extraction:
245
-
246
-
*`DefaultKeyLookup(keyLookup string, authScheme string)`: This is the function that implements the default `KeyLookup` behavior, exposed to be used as a component of custom parsing logic
247
-
*`MultipleKeySourceLookup(keyLookups []string, authScheme string)`: Creates a CustomKeyLookup function that checks each listed source using the above function until a key is found or the options are all exhausted. For example, `MultipleKeySourceLookup([]string{"header:Authorization", "header:x-api-key", "cookie:apikey"}, "Bearer")` would first check the standard Authorization header, checks the `x-api-key` header next, and finally checks for a cookie named `apikey`. If any of these contain a valid API key, the request continues. Otherwise, an error is returned.
Copy file name to clipboardExpand all lines: docs/whats_new.md
+25-2Lines changed: 25 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ Here's a quick overview of the changes in Fiber `v3`:
48
48
49
49
## Drop for old Go versions
50
50
51
-
Fiber `v3` drops support for Go versions below `1.24`. We recommend upgrading to Go `1.24` or higher to use Fiber `v3`.
51
+
Fiber `v3` drops support for Go versions below `1.25`. We recommend upgrading to Go `1.25` or higher to use Fiber `v3`.
52
52
53
53
## 🚀 App
54
54
@@ -1093,7 +1093,7 @@ The `Expiration` field in the CSRF middleware configuration has been renamed to
1093
1093
1094
1094
### EncryptCookie
1095
1095
1096
-
Added support for specifying Key length when using `encryptcookie.GenerateKey(length)`. This allows the user to generate keys compatible with `AES-128`, `AES-192`, and `AES-256` (Default).
1096
+
Added support for specifying key length when using `encryptcookie.GenerateKey(length)`. Keys must be base64-encoded and may be 16, 24, or 32 bytes when decoded, supporting AES-128, AES-192, and AES-256 (default).
1097
1097
1098
1098
### EnvVar
1099
1099
@@ -1113,6 +1113,7 @@ Refer to the [healthcheck middleware migration guide](./middleware/healthcheck.m
1113
1113
### KeyAuth
1114
1114
1115
1115
The keyauth middleware was updated to introduce a configurable `Realm` field for the `WWW-Authenticate` header.
1116
+
The old string-based `KeyLookup` configuration has been replaced with an `Extractor` field. Use helper functions like `keyauth.FromHeader`, `keyauth.FromAuthHeader`, or `keyauth.FromCookie` to define where the key should be retrieved from. Multiple sources can be combined with `keyauth.Chain`. See the migration guide below.
1116
1117
1117
1118
### Logger
1118
1119
@@ -1938,6 +1939,28 @@ Passwords configured for BasicAuth must now be pre-hashed. If no prefix is suppl
1938
1939
You can also set the optional `HeaderLimit` and `Charset`
1939
1940
options to further control authentication behavior.
1940
1941
1942
+
#### KeyAuth
1943
+
1944
+
The keyauth middleware was updated to introduce a configurable `Realm` field for the `WWW-Authenticate` header.
1945
+
The old string-based `KeyLookup` configuration has been replaced with an `Extractor` field, and the `AuthScheme` field has been removed. The auth scheme is now inferred from the extractor used (e.g., `keyauth.FromAuthHeader`). Use helper functions like `keyauth.FromHeader`, `keyauth.FromAuthHeader`, or `keyauth.FromCookie` to define where the key should be retrieved from. Multiple sources can be combined with `keyauth.Chain`.
0 commit comments