-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
191 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
"net/http" | ||
|
||
"github.com/golang-jwt/jwt" | ||
"github.com/goschtalt/goschtalt" | ||
"github.com/xmidt-org/bascule" | ||
"github.com/xmidt-org/clortho" | ||
Check failure on line 14 in basculehttp/bearerTokenFactory.go GitHub Actions / ci / Build Go Program
Check failure on line 14 in basculehttp/bearerTokenFactory.go GitHub Actions / ci / Go Unit Tests
|
||
"github.com/xmidt-org/clortho/clorthofx" | ||
Check failure on line 15 in basculehttp/bearerTokenFactory.go GitHub Actions / ci / Build Go Program
Check failure on line 15 in basculehttp/bearerTokenFactory.go GitHub Actions / ci / Go Unit Tests
|
||
|
@@ -26,17 +25,16 @@ var ( | |
ErrInvalidPrincipal = errors.New("invalid principal") | ||
ErrInvalidToken = errors.New("token isn't valid") | ||
ErrUnexpectedClaims = errors.New("claims wasn't MapClaims as expected") | ||
|
||
ErrNilResolver = errors.New("resolver cannot be nil") | ||
ErrNilResolver = errors.New("resolver cannot be nil") | ||
) | ||
|
||
// BearerTokenFactory parses and does basic validation for a JWT token, | ||
// converting it into a bascule Token. | ||
type BearerTokenFactory struct { | ||
fx.In | ||
DefaultKeyID string `name:"default_key_id"` | ||
Resolver clortho.Resolver | ||
Parser bascule.JWTParser `optional:"true"` | ||
DefaultKeyID string `name:"default_key_id" optional:"true"` | ||
Resolver clortho.Resolver `name:"key_resolver" optional:"true"` | ||
Parser bascule.JWTParser `name:"parser" optional:"true"` | ||
Leeway bascule.Leeway `name:"jwt_leeway" optional:"true"` | ||
} | ||
|
||
|
@@ -99,20 +97,24 @@ func (btf BearerTokenFactory) ParseAndValidate(ctx context.Context, _ *http.Requ | |
// ProvideBearerTokenFactory uses the key given to unmarshal configuration | ||
// needed to build a bearer token factory. It provides a constructor option | ||
// with the bearer token factory. | ||
func ProvideBearerTokenFactory(configKey string, optional bool) fx.Option { | ||
func ProvideBearerTokenFactory(optional bool) fx.Option { | ||
return fx.Options( | ||
clorthofx.Provide(), | ||
fx.Provide( | ||
fx.Annotated{ | ||
Name: "jwt_leeway", | ||
Target: goschtalt.UnmarshalFunc[bascule.Leeway](fmt.Sprintf("%s.leeway", configKey)), | ||
}, | ||
fx.Annotated{ | ||
Group: "bascule_constructor_options", | ||
Target: func(f BearerTokenFactory) (COption, error) { | ||
if f.Parser == nil { | ||
f.Parser = bascule.DefaultJWTParser | ||
} | ||
|
||
if f.Resolver == nil { | ||
if optional { | ||
return nil, nil | ||
} | ||
return nil, ErrNilResolver | ||
} | ||
|
||
return WithTokenFactory(BearerAuthorization, f), nil | ||
}, | ||
}, | ||
|
Oops, something went wrong.