Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
sreya merged 25 commits intomainfromjon/jwt
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
b5d939e
feat: add jwt pkg
sreyaOct 1, 2024
6025c7b
update make gen
sreyaOct 2, 2024
8b235be
Refactor JWT package to modularize key functions
sreyaOct 2, 2024
843de38
Remove unused JWT test file from repository
sreyaOct 2, 2024
099544f
Refactor JWT key functions and add tests
sreyaOct 2, 2024
acc4db3
Rename VerifyFn to ParseFn in JWT tests
sreyaOct 2, 2024
b4973a8
Remove unused JWE test file
sreyaOct 2, 2024
f7d7c95
Refactor JWT test structs to use public field names
sreyaOct 2, 2024
3ba8ad3
Refactor JWT to use new crypto key management system
sreyaOct 3, 2024
73c902c
Refactor JWT package for improved modularity and clarity
sreyaOct 3, 2024
e348a7a
mv dir
sreyaOct 3, 2024
c7489b4
update references
sreyaOct 3, 2024
d890ea2
refactor interfaces
sreyaOct 3, 2024
67ccd5c
refactor dbkeycache
sreyaOct 3, 2024
1a81c7a
Refactor JWT utility options for flexibility
sreyaOct 3, 2024
e529c4a
Enhance key generation and JWT error messages
sreyaOct 3, 2024
437e587
Update cryptographic key length requirements
sreyaOct 3, 2024
54214e2
Refactor key provider interfaces in JWT utilities
sreyaOct 3, 2024
93603a2
Refactor dbCache to remove feature validation
sreyaOct 3, 2024
e654a65
Refactor cryptokeys and jwtutils interfaces and logic
sreyaOct 3, 2024
0efabfd
Remove unused test code and mock cleanup
sreyaOct 3, 2024
e065356
Remove cryptokeys keycachemock from Makefile
sreyaOct 3, 2024
938bdda
Add feature validation to dbCache key methods
sreyaOct 3, 2024
48b1b3b
fmt
sreyaOct 3, 2024
1dd2205
Add initialization comment for db key cache timer
sreyaOct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Refactor JWT utility options for flexibility
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
@sreya
sreya committedOct 3, 2024
commit1a81c7ad548182aee42af81539d11ed04d15aaa5
13 changes: 11 additions & 2 deletionscoderd/jwtutils/jwe.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,9 +62,18 @@ func Encrypt(ctx context.Context, e EncryptKeyer, claims Claims) (string, error)
return base64.RawURLEncoding.EncodeToString(serialized), nil
}

// DecryptOptions are options for decrypting a JWE.
type DecryptOptions struct {
RegisteredClaims jwt.Expected

// The following should only be used for JWEs.
KeyAlgorithm jose.KeyAlgorithm
ContentEncryptionAlgorithm jose.ContentEncryption
}

// Decrypt decrypts the token using the provided key. It unmarshals into the provided claims.
func Decrypt(ctx context.Context, d DecryptKeyer, token string, claims Claims, opts ...func(*ParseOptions)) error {
options :=ParseOptions{
func Decrypt(ctx context.Context, d DecryptKeyer, token string, claims Claims, opts ...func(*DecryptOptions)) error {
options :=DecryptOptions{
RegisteredClaims: jwt.Expected{
Time: time.Now(),
},
Expand Down
22 changes: 20 additions & 2 deletionscoderd/jwtutils/jws.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
)
Expand DownExpand Up@@ -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.
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(*ParseOptions)) error {
options :=ParseOptions{
func Verify(ctx context.Context, v VerifyKeyer, token string, claims Claims, opts ...func(*VerifyOptions)) error {
options :=VerifyOptions{
RegisteredClaims: jwt.Expected{
Time: time.Now(),
},
Expand Down
28 changes: 0 additions & 28 deletionscoderd/jwtutils/jwt.go
View file
Open in desktop

This file was deleted.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp