/
auth.go
66 lines (48 loc) · 1.76 KB
/
auth.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
60
61
62
63
64
65
66
package auth
import (
"context"
"github.com/dantin/cubit/xmpp"
)
const saslNamespace = "urn:ietf:params:xml:ns:xmpp-sasl"
// Authenticator defines a generic authenticator state machine.
type Authenticator interface {
// Mechanism returns authenticator mechanism name.
Mechanism() string
// Username returns authenticated username in case
// authentication process has been completed.
Username() string
// Authenticated returns whether or not user has been authenticated.
Authenticated() bool
// UsesChannelBinding returns whether or not this authenticator
// requires channel binding bytes.
UsesChannelBinding() bool
// ProcessElement process an incoming authenticator element.
ProcessElement(context.Context, xmpp.XElement) error
// Reset resets authenticator internal state.
Reset()
}
// SASLError represents specific SASL error type.
type SASLError struct {
reason string
}
func newSASLError(reason string) error {
return &SASLError{reason}
}
// Element returs sasl error XML representation.
func (se *SASLError) Element() xmpp.XElement {
return xmpp.NewElementName(se.reason)
}
// Error satisfies error interface.
func (se *SASLError) Error() string {
return se.reason
}
var (
// ErrSASLIncorrectEncoding represents a 'incorrect-encoding' authentication error.
ErrSASLIncorrectEncoding = newSASLError("incorrect-encoding")
// ErrSASLMalformedRequest represents a 'malformed-request' authentication error.
ErrSASLMalformedRequest = newSASLError("malformed-request")
// ErrSASLNotAuthorized represents a 'not-authorized' authentication error.
ErrSASLNotAuthorized = newSASLError("not-authorized")
// ErrSASLTemporaryAuthFailure represents a 'temporary-auth-failure' authentication error.
ErrSASLTemporaryAuthFailure = newSASLError("temporary-auth-failure")
)