用户加密机制设计初步完成

This commit is contained in:
veypi
2021-10-21 18:09:40 +08:00
parent cd7029c298
commit 82b64a4bb2
40 changed files with 1027 additions and 322 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
package base
import (
"OneAuth/libs/auth"
"OneAuth/libs/oerr"
"OneAuth/libs/tools"
"github.com/json-iterator/go"
@@ -17,7 +16,7 @@ var json = jsoniter.ConfigFastest
type ApiHandler struct {
OneBD.BaseHandler
auth.UserHandler
UserHandler
}
func (h *ApiHandler) Init(m OneBD.Meta) error {
+47
View File
@@ -0,0 +1,47 @@
package base
import (
"OneAuth/libs/oerr"
"OneAuth/libs/token"
"OneAuth/models"
"github.com/veypi/OneBD"
"github.com/veypi/OneBD/rfc"
)
type UserHandler struct {
Payload *token.PayLoad
ignoreMethod map[rfc.Method]bool
}
func (a *UserHandler) Init(m OneBD.Meta) error {
if a.ignoreMethod != nil && a.ignoreMethod[m.Method()] {
return nil
}
return a.ParsePayload(m)
}
func (a *UserHandler) ParsePayload(m OneBD.Meta) error {
a.Payload = new(token.PayLoad)
tokenStr := m.GetHeader("auth_token")
if tokenStr == "" {
return oerr.NotLogin
}
ok, err := token.ParseToken(tokenStr, a.Payload)
if ok {
return nil
}
return oerr.NotLogin.Attach(err)
}
func (a *UserHandler) Ignore(methods ...rfc.Method) {
if a.ignoreMethod == nil {
a.ignoreMethod = make(map[rfc.Method]bool)
}
for _, m := range methods {
a.ignoreMethod[m] = true
}
}
func (a *UserHandler) GetAuth(ResourceID string, ResourceUUID ...string) models.AuthLevel {
return a.Payload.GetAuth(ResourceID, ResourceUUID...)
}