Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
86 lines (70 loc) · 2.84 KB
/
Copy patherrors.go
File metadata and controls
86 lines (70 loc) · 2.84 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package grantable
import (
"errors"
"net/http"
)
var (
// ErrNotFound is what a Store answers for a row it does not hold, or no
// longer holds in the state asked for.
ErrNotFound = errors.New("grantable: not found")
// ErrRequestUnavailable means the authorization request is unknown,
// expired, or already answered. The consent page shows it as gone.
ErrRequestUnavailable = errors.New("grantable: the authorization request is unavailable")
// ErrInvalidToken means a bearer token is unknown, expired, revoked,
// issued for another resource, or grants nothing any more. Callers must
// not tell the client which.
ErrInvalidToken = errors.New("grantable: invalid token")
ErrMissingStore = errors.New("grantable: a Store is required")
ErrMissingIssuer = errors.New("grantable: an issuer is required")
)
// The error codes of RFC 6749 section 5.2 and 4.1.2.1, RFC 7591 section 3.2.2
// and RFC 8707 section 2.
const (
CodeInvalidRequest = "invalid_request"
CodeInvalidClient = "invalid_client"
CodeInvalidGrant = "invalid_grant"
CodeInvalidScope = "invalid_scope"
CodeInvalidTarget = "invalid_target"
CodeUnauthorizedClient = "unauthorized_client"
CodeUnsupportedGrantType = "unsupported_grant_type"
CodeUnsupportedResponseType = "unsupported_response_type"
CodeAccessDenied = "access_denied"
CodeInvalidRedirectURI = "invalid_redirect_uri"
CodeInvalidClientMetadata = "invalid_client_metadata"
CodeServerError = "server_error"
)
// Error is a refusal in the shape the OAuth specifications give it: a code
// a client acts on, a description a developer reads, and the HTTP status it
// travels with.
type Error struct {
Status int
Code string
Description string
}
func (self *Error) Error() string {
return "grantable: " + self.Code + ": " + self.Description
}
func refuse(status int, code, description string) *Error {
return &Error{Status: status, Code: code, Description: description}
}
func invalidRequest(description string) *Error {
return refuse(http.StatusBadRequest, CodeInvalidRequest, description)
}
func invalidClient(description string) *Error {
return refuse(http.StatusUnauthorized, CodeInvalidClient, description)
}
func invalidGrant(description string) *Error {
return refuse(http.StatusBadRequest, CodeInvalidGrant, description)
}
func invalidScope(description string) *Error {
return refuse(http.StatusBadRequest, CodeInvalidScope, description)
}
func invalidTarget(description string) *Error {
return refuse(http.StatusBadRequest, CodeInvalidTarget, description)
}
func invalidRedirectURI(description string) *Error {
return refuse(http.StatusBadRequest, CodeInvalidRedirectURI, description)
}
func invalidClientMetadata(description string) *Error {
return refuse(http.StatusBadRequest, CodeInvalidClientMetadata, description)
}