...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package server
16
17 import (
18 "context"
19 "net/http"
20
21 "github.com/go-kivik/kivik/v4"
22 internal "github.com/go-kivik/kivik/v4/int/errors"
23 "github.com/go-kivik/kivik/v4/x/server/auth"
24 )
25
26 type userStores []auth.UserStore
27
28 var _ auth.UserStore = userStores{}
29
30 func (s userStores) Validate(ctx context.Context, username, password string) (*auth.UserContext, error) {
31 for _, store := range s {
32 userCtx, err := store.Validate(ctx, username, password)
33 if kivik.HTTPStatus(err) == http.StatusNotFound {
34 continue
35 }
36 return userCtx, err
37 }
38 return nil, &internal.Error{Status: http.StatusUnauthorized, Message: "Invalid username or password"}
39 }
40
41 func (s userStores) UserCtx(ctx context.Context, username string) (*auth.UserContext, error) {
42 for _, store := range s {
43 userCtx, err := store.UserCtx(ctx, username)
44 if kivik.HTTPStatus(err) == http.StatusNotFound {
45 continue
46 }
47 return userCtx, err
48 }
49 return nil, &internal.Error{Status: http.StatusNotFound, Message: "User not found"}
50 }
51
View as plain text