-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_plain.go
More file actions
42 lines (35 loc) · 959 Bytes
/
auth_plain.go
File metadata and controls
42 lines (35 loc) · 959 Bytes
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
package xmpp
import (
"bytes"
"encoding/base64"
)
// PlainAuth implements a plain SASL authentication
type PlainAuth struct {
Username string
Password string
}
// NewPlainAuthenticator instantiates a PLAIN authenticator using provided credentials
func NewPlainAuthenticator(creds Credentials) Authenticator {
return &PlainAuth{
Username: creds.Username,
Password: creds.Password,
}
}
// Name returns the name of the authenticator
func (auth *PlainAuth) Name() string {
return "PLAIN"
}
// Data returns authentication data encoded for PLAIN mechanism
func (auth *PlainAuth) Data() string {
dataBytes := bytes.Join([][]byte{
{},
[]byte(auth.Username),
[]byte(auth.Password),
}, []byte{0})
return base64.StdEncoding.EncodeToString(dataBytes)
}
// Challenge satisfies Authenticator interface. It returns an empty string since
// PLAIN mechanism doesn't support challenges.
func (auth *PlainAuth) Challenge(string) string {
return ""
}