-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
43 lines (40 loc) · 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
package config
import (
"github.com/goal-web/auth"
"github.com/goal-web/contracts"
"github.com/goal-web/supports/class"
"github.com/golang-jwt/jwt"
"github.com/qbhy/goal-piplin/app/models"
"time"
)
var UserClass = class.Make[contracts.Authenticatable](&models.User{})
func init() {
configs["auth"] = func(env contracts.Env) any {
return auth.Config{
Defaults: auth.Defaults{
Guard: env.StringOptional("auth.default", "jwt"),
User: env.StringOptional("auth.user", "db"),
},
Guards: map[string]contracts.Fields{
"jwt": {
"driver": "jwt",
"secret": env.GetString("auth.jwt.secret"),
"method": jwt.SigningMethodHS256,
"lifetime": 60 * 60 * 24 * time.Second,
"provider": "db",
},
"session": {
"driver": "session",
"provider": "db",
"session_key": env.StringOptional("auth.session.key", "auth_session"),
},
},
Users: map[string]contracts.Fields{
"db": {
"driver": "db",
"class": UserClass,
},
},
}
}
}