-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auth.go
53 lines (40 loc) · 1.1 KB
/
Auth.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
52
53
package main
import (
"fmt"
// traffic
// auth
"github.com/qor/auth"
"github.com/qor/auth/claims"
"github.com/qor/auth/providers/password"
// mongo
// bcrypt
"golang.org/x/crypto/bcrypt"
// jwt
)
type any = interface{}
var Auth = auth.New(&auth.Config{
UserModel: User{},
})
func init() {
Auth.RegisterProvider(password.New(&password.Config{
Encryptor: Encryptor{},
AuthorizeHandler: AuthorizeHandler,
RegisterHandler: RegisterHandler,
}))
}
type Encryptor struct{}
func (e Encryptor) Digest(password string) (string, error) {
p, err := bcrypt.GenerateFromPassword([]byte(password), 10)
return string(p), err
}
func (e Encryptor) Compare(hashedPassword string, password string) error {
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
}
func AuthorizeHandler(ctx *auth.Context) (*claims.Claims, error) {
// TODO authentication
return nil, fmt.Errorf("AuthorizeHandler not implemented")
}
func RegisterHandler(ctx *auth.Context) (*claims.Claims, error) {
// TODO register the authentication
return nil, fmt.Errorf("RegisterHandler not implemented")
}