1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
package openapi3filter
import (
"fmt"
"strings"
"github.com/getkin/kin-openapi/openapi3"
)
type AuthenticationInput struct {
RequestValidationInput *RequestValidationInput
SecuritySchemeName string
SecurityScheme *openapi3.SecurityScheme
Scopes []string
}
func (input *AuthenticationInput) NewError(err error) error {
if err == nil {
scopes := input.Scopes
if len(scopes) == 0 {
err = fmt.Errorf("Security requirement '%s' failed",
input.SecuritySchemeName)
} else {
err = fmt.Errorf("Security requirement '%s' (scopes: '%s') failed",
input.SecuritySchemeName,
strings.Join(input.Scopes, "', '"))
}
}
return &RequestError{
Input: input.RequestValidationInput,
Reason: "Authorization failed",
Err: err,
}
}
|