- Notifications
You must be signed in to change notification settings - Fork929
feat: add jwt pkg#14928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
feat: add jwt pkg#14928
Changes from1 commit
b5d939e
6025c7b
8b235be
843de38
099544f
acc4db3
b4973a8
f7d7c95
3ba8ad3
73c902c
e348a7a
c7489b4
d890ea2
67ccd5c
1a81c7a
e529c4a
437e587
54214e2
93603a2
e654a65
0efabfd
e065356
938bdda
48b1b3b
1dd2205
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Refactor JWT utility code to replace `ParseOptions` with more specific`VerifyOptions` and `DecryptOptions`. This change enhances clarity andflexibility, accommodating different needs for JWS and JWE operations. Updatetests to align with the refactored structure, ensuring robust coverage andfunctionality verification.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11,6 +11,16 @@ import ( | ||
"golang.org/x/xerrors" | ||
) | ||
const ( | ||
keyIDHeaderKey = "kid" | ||
) | ||
// Claims defines the payload for a JWT. Most callers | ||
// should embed jwt.Claims | ||
type Claims interface { | ||
Validate(jwt.Expected) error | ||
} | ||
const ( | ||
signingAlgo = jose.HS512 | ||
) | ||
@@ -60,9 +70,17 @@ func Sign(ctx context.Context, s SignKeyer, claims Claims) (string, error) { | ||
return compact, nil | ||
} | ||
// VerifyOptions are options for verifying a JWT. | ||
type VerifyOptions struct { | ||
RegisteredClaims jwt.Expected | ||
// The following are only used for JWSs. | ||
sreya marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
SignatureAlgorithm jose.SignatureAlgorithm | ||
} | ||
// Verify verifies that a token was signed by the provided key. It unmarshals into the provided claims. | ||
func Verify(ctx context.Context, v VerifyKeyer, token string, claims Claims, opts ...func(*VerifyOptions)) error { | ||
options :=VerifyOptions{ | ||
RegisteredClaims: jwt.Expected{ | ||
Time: time.Now(), | ||
}, | ||
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.