-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
42 lines (34 loc) · 867 Bytes
/
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
package context
type AuthInfo interface {
IdStr() string
}
/*
type AuthInterface interface {
Validate() error
GenerateToken(secret []byte) (string, error)
ParseToken(token string, secret []byte) error
}
type Authorization struct {
AuthInfo `json:"auth"`
jwt.RegisteredClaims
AuthInfoRaw string `json:"-"`
}
func (x *Authorization) Validate() error {
return nil
}
func (x *Authorization) GenerateToken(secret []byte) (string, error) {
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, x)
token, err := tokenClaims.SignedString(secret)
return token, err
}
func (x *Authorization) ParseToken(token string, secret []byte) error {
_, err := jwti.ParseToken(x, token, secret)
if err != nil {
return err
}
x.ID = x.AuthInfo.IdStr()
authBytes, _ := json.Marshal(x.AuthInfo)
x.AuthInfoRaw = stringsi.BytesToString(authBytes)
return nil
}
*/