Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
65 lines (50 loc) · 2.03 KB
/
Copy patherrors.go
File metadata and controls
65 lines (50 loc) · 2.03 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
package sociable
import (
"errors"
"fmt"
)
var (
ErrUnknownDriver = errors.New("sociable: unknown driver")
// ErrDriverNotConfigured means the driver has no client id, no endpoints
// or no redirect URL. Refuse the route rather than redirect.
ErrDriverNotConfigured = errors.New("sociable: driver not configured")
ErrMissingKeyOrSession = errors.New("sociable: a Key or a Session is required")
ErrSessionSealed = errors.New("sociable: the cookie cannot be opened")
)
var (
// ErrInvalidState means the callback was not started here, was already
// used, or came back with another state.
ErrInvalidState = errors.New("sociable: invalid state")
// ErrAuthorization is what every provider refusal matches.
ErrAuthorization = errors.New("sociable: the provider refused")
// ErrAccessDenied is the refusal that means the person said no.
ErrAccessDenied = fmt.Errorf("%w: access denied", ErrAuthorization)
// ErrExchange means the code could not be exchanged for a token.
ErrExchange = errors.New("sociable: token exchange failed")
// ErrProfile means the provider would not describe the person.
ErrProfile = errors.New("sociable: could not read the profile")
// ErrIDToken means the ID token failed verification: signature, issuer,
// audience, expiry or nonce.
ErrIDToken = errors.New("sociable: the id token could not be verified")
)
// AuthorizationError is a refusal the provider sent back on the redirect, in
// the shape RFC 6749 section 4.1.2.1 defines.
type AuthorizationError struct {
Code string
Description string
URI string
}
func (self *AuthorizationError) Error() string {
if self.Description == "" {
return "sociable: the provider refused: " + self.Code
}
return "sociable: the provider refused: " + self.Code + ": " + self.Description
}
// Is makes every refusal match ErrAuthorization, and access_denied match
// ErrAccessDenied as well.
func (self *AuthorizationError) Is(target error) bool {
if target == ErrAccessDenied {
return self.Code == "access_denied"
}
return target == ErrAuthorization
}