File: authentication_input.go

package info (click to toggle)
golang-github-getkin-kin-openapi 0.32.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,116 kB
  • sloc: makefile: 3
file content (34 lines) | stat: -rw-r--r-- 785 bytes parent folder | download | duplicates (2)
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,
	}
}