-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.go
More file actions
40 lines (32 loc) · 736 Bytes
/
store.go
File metadata and controls
40 lines (32 loc) · 736 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
package oauth2
import (
"fmt"
"github.com/botopolis/bot"
"golang.org/x/oauth2"
)
// store is responsible for storing tokens for individual
// users by oauth service
type store struct {
namespace string
store *bot.Brain
}
func newStore(namespace string, b *bot.Brain) *store {
return &store{
namespace: namespace,
store: b,
}
}
func (s store) key(user string) string {
return fmt.Sprintf("auth:%s:%s", s.namespace, user)
}
func (s store) Get(user string) (oauth2.Token, bool) {
var t oauth2.Token
err := s.store.Get(s.key(user), &t)
return t, err == nil
}
func (s store) Set(user string, t oauth2.Token) {
s.store.Set(s.key(user), &t)
}
func (s store) Delete(user string) {
s.store.Delete(s.key(user))
}