-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
59 lines (52 loc) · 2.07 KB
/
errors.go
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
package ohauth
import (
"fmt"
"net/url"
)
// Error defines an OAuth error with fields specified in rfc6749
type Error struct {
Code string `json:"error"`
Description string `json:"error_description,omitempty"`
}
// NewError creates a populated error instance
func NewError(ec, desc string) *Error {
return &Error{ec, desc}
}
func (e *Error) Error() string {
return fmt.Sprintf("%s - %s", e.Code, e.Description)
}
// Values returns a representation of an Error that can be used as query
// parameters in a redirect uri
func (e *Error) Values() url.Values {
v := url.Values{}
v.Set("error", e.Code)
v.Set("error_description", e.Description)
return v
}
// Error codes as specified throughout rfc6749
const (
AccessDenied = "access_denied"
InvalidClient = "invalid_client"
InvalidGrant = "invalid_grant"
InvalidRequest = "invalid_request"
InvalidScope = "invalid_scope"
ServerError = "server_error"
TemporarilyUnavailable = "temporarily_unavailable"
UnauthorizedClient = "unauthorized_client"
UnsupportedGrantType = "unsupported_grant_type"
UnsupportedResponseType = "unsupported_response_type"
)
// Common errors that can occur while processing authorization and token
// requests
var (
ErrClientNotFound = NewError(InvalidClient, "client not found")
ErrScopeNotAllowed = NewError(InvalidScope, "client cannot offer requested scope")
ErrWrongGrant = NewError(InvalidRequest, "client cannot use specified grant type")
ErrInvalidGrant = NewError(InvalidRequest, "invalid grant type")
ErrUnexpected = NewError(ServerError, "unexpected error occured")
ErrUnsupportResponseType = NewError(UnsupportedResponseType, "unsupported response type")
ErrBadRedirect = NewError(InvalidRequest, "invalid redirect uri")
ErrAccessDenied = NewError(AccessDenied, "access denied")
ErrUnauthorized = NewError(UnauthorizedClient, "unauthorized client")
ErrCodeUsed = NewError(InvalidRequest, "authorization code has already been used")
)