-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_anon.go
51 lines (39 loc) · 1.52 KB
/
auth_anon.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
package main
// Anonymous authentication is used only at account creation time.
import (
"errors"
"time"
"github.com/tinode/chat/server/auth"
"github.com/tinode/chat/server/store"
"github.com/tinode/chat/server/store/types"
)
type AnonAuth struct{}
var user_lifetime time.Duration
func (AnonAuth) Init(unused string) error {
return nil
}
// Adding a record is a noop. Just report success.
func (AnonAuth) AddRecord(uid types.Uid, secret []byte, lifetime time.Duration) (int, auth.AuthErr) {
return auth.LevelAnon, auth.NewErr(auth.NoErr, nil)
}
// Updating a record is a noop. Just report success.
func (AnonAuth) UpdateRecord(uid types.Uid, secret []byte, lifetime time.Duration) auth.AuthErr {
return auth.NewErr(auth.NoErr, nil)
}
// Anonymous authentication is not supported. It's used only at account
// creation time.
func (AnonAuth) Authenticate(secret []byte) (types.Uid, int, time.Time, auth.AuthErr) {
return types.ZeroUid, auth.LevelNone, time.Time{},
auth.NewErr(auth.ErrUnsupported, errors.New("anon auth: Authenticate is not supported"))
}
// Anonymous login does not use secret, any secret is fine.
func (AnonAuth) IsUnique(secret []byte) (bool, auth.AuthErr) {
return true, auth.NewErr(auth.NoErr, nil)
}
func (AnonAuth) GenSecret(uid types.Uid, authLvl int, lifetime time.Duration) ([]byte, time.Time, auth.AuthErr) {
return nil, time.Time{}, auth.NewErr(auth.ErrUnsupported, errors.New("anon auth: GenSecret is not supported"))
}
func init() {
var auth AnonAuth
store.RegisterAuthScheme("anonymous", auth)
}