Skip to content

Commit 1df126e

Browse files
committed
docs(jwt): improve documentation of SigningKey, SigningKeys and KeyFunc
1 parent 6c6a45b commit 1df126e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

middleware/jwt.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ type (
2929
// ErrorHandlerWithContext is almost identical to ErrorHandler, but it's passed the current context.
3030
ErrorHandlerWithContext JWTErrorHandlerWithContext
3131

32-
// Signing key to validate token. Used as fallback if KeyFunc is nil or SigningKeys has length 0.
33-
// Required. This or SigningKeys or KeyFunc.
32+
// Signing key to validate token.
33+
// This is one of the three options to provide a token validation key.
34+
// The order of precedence is a user-defined KeyFunc, SigningKeys and SigningKey.
35+
// Required if neither user-defined KeyFunc nor SigningKeys is provided.
3436
SigningKey interface{}
3537

36-
// Map of signing keys to validate token with kid field usage. Used as fallback if KeyFunc is nil.
37-
// Required. This or SigningKey or KeyFunc.
38+
// Map of signing keys to validate token with kid field usage.
39+
// This is one of the three options to provide a token validation key.
40+
// The order of precedence is a user-defined KeyFunc, SigningKeys and SigningKey.
41+
// Required if neither user-defined KeyFunc nor SigningKey is provided.
3842
SigningKeys map[string]interface{}
3943

40-
// Signing method, used to check token signing method.
44+
// Signing method used to check the token's signing algorithm.
4145
// Optional. Default value HS256.
4246
SigningMethod string
4347

@@ -64,11 +68,15 @@ type (
6468
// Optional. Default value "Bearer".
6569
AuthScheme string
6670

67-
// KeyFunc defines a function to supply the key for a token verification.
71+
// KeyFunc defines a user-defined function that supplies the public key for a token validation.
72+
// The function shall take care of verifying the signing algorithm and selecting the proper key.
73+
// A user-defined KeyFunc can be useful if tokens are issued by an external party.
74+
//
6875
// When a user-defined KeyFunc is provided, SigningKey, SigningKeys, and SigningMethod are ignored.
69-
// Required. This or SigningKey or SigningKeys.
76+
// This is one of the three options to provide a token validation key.
77+
// The order of precedence is a user-defined KeyFunc, SigningKeys and SigningKey.
78+
// Required if neither SigningKeys nor SigningKey is provided.
7079
// Default to an internal implementation verifying the signing algorithm and selecting the proper key.
71-
// See: `jwt.Keyfunc`
7280
KeyFunc jwt.Keyfunc
7381
}
7482

0 commit comments

Comments
 (0)