-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config to chained validator (#692)
* Add config to chained validator * Add tests with mock oidc server * simplify config, remove cors middleware * go mod tidy * remove IssuerURL * better log statements * better flow
- Loading branch information
Showing
13 changed files
with
161 additions
and
191 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package token | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type ChainedValidator struct{ validators []ValidatorInterface } | ||
|
||
var _ ValidatorInterface = &ChainedValidator{} | ||
var errNoValidatorsFound = errors.New("no validators found") | ||
|
||
func NewChainedValidator(validators ...ValidatorInterface) *ChainedValidator { | ||
return &ChainedValidator{validators} | ||
} | ||
|
||
func (v *ChainedValidator) ValidateToken(ctx context.Context, token string) (TokenPrincipal, error) { | ||
var errs []error | ||
|
||
for _, validator := range v.validators { | ||
principal, err := validator.ValidateToken(ctx, token) | ||
if principal != nil { | ||
return principal, nil | ||
} | ||
errs = append(errs, err) | ||
} | ||
|
||
if len(errs) > 0 { | ||
return nil, fmt.Errorf("no issuers could validate token: %w", errors.Join(errs...)) | ||
} | ||
|
||
return nil, errNoValidatorsFound | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.