Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
66 lines (57 loc) · 2.52 KB
/
Copy patherrors.go
File metadata and controls
66 lines (57 loc) · 2.52 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package forwardauth
import "errors"
// Error definitions for ForwardAuth.
var (
// Configuration errors
ErrNoPasswordConfigured = errors.New("password authentication enabled but no passwords configured")
// ErrHeaderAuthTrustUnspecified indicates header-based authentication is
// enabled without stating whether the identity headers can be trusted.
// Set HeaderAuthTrustFunc to say which requests may supply them, or
// HeaderAuthAllowUntrustedHeaders to accept them from any caller.
//
// Neither replaces the proxy stripping the client's identity headers and
// setting its own. What a trust check does and does not establish is
// documented on HeaderAuthTrustFunc and stated only there -- paraphrasing
// it here is what left this comment recommending a peer check, which is
// the one check the rule exists to rule out.
ErrHeaderAuthTrustUnspecified = errors.New("header auth requires HeaderAuthTrustFunc or HeaderAuthAllowUntrustedHeaders")
ErrNoUserCheckFunc = errors.New("header authentication enabled but no user check function provided")
ErrInvalidConfig = errors.New("invalid configuration")
// Authentication errors
ErrNotAuthenticated = errors.New("not authenticated")
ErrInvalidPassword = errors.New("invalid password")
ErrUserNotFound = errors.New("user not found")
ErrSessionRequired = errors.New("session required")
ErrStepUpRequired = errors.New("step-up authentication required")
ErrSessionStoreError = errors.New("session store error")
// HTTP status related
ErrUnauthorized = errors.New("unauthorized")
ErrForbidden = errors.New("forbidden")
)
// ErrorCode represents an error code for API responses.
type ErrorCode string
const (
ErrorCodeUnauthorized ErrorCode = "unauthorized"
ErrorCodeInvalidPassword ErrorCode = "invalid_password"
ErrorCodeUserNotFound ErrorCode = "user_not_found"
ErrorCodeSessionRequired ErrorCode = "session_required"
ErrorCodeStepUpRequired ErrorCode = "step_up_required"
ErrorCodeSessionError ErrorCode = "session_error"
ErrorCodeInternalError ErrorCode = "internal_error"
)
// ErrorResponse represents an error response structure.
type ErrorResponse struct {
OK bool `json:"ok"`
Code ErrorCode `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Status int `json:"status,omitempty"`
}
// NewErrorResponse creates a new error response.
func NewErrorResponse(code ErrorCode, message string, status int) *ErrorResponse {
return &ErrorResponse{
OK: false,
Code: code,
Message: message,
Status: status,
}
}