-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_store.go
48 lines (41 loc) · 1007 Bytes
/
client_store.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
package sqlite
import (
"context"
"github.com/go-oauth2/oauth2/v4"
"github.com/go-oauth2/oauth2/v4/models"
)
type ClientStore struct {
repository *ClientRepository
}
func NewClientStore(filename string) (*ClientStore, error) {
repo, err := NewClientRepository(filename)
if err != nil {
return nil, err
}
return &ClientStore{
repository: repo,
}, nil
}
func (c *ClientStore) Set(ctx context.Context, info oauth2.ClientInfo) error {
return c.repository.Insert(&ClientItem{
Id: info.GetID(),
Secret: info.GetSecret(),
Domain: info.GetDomain(),
UserId: info.GetUserID(),
})
}
func (c *ClientStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error) {
item, err := c.repository.GetById(id)
if err != nil {
return nil, err
}
return &models.Client{
ID: item.Id,
Secret: item.Secret,
Domain: item.Domain,
UserID: item.UserId,
}, nil
}
func (c *ClientStore) RemoveByID(ctx context.Context, id string) error {
return c.repository.RemoveById(id)
}