You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
910 B
36 lines
910 B
package authorize |
|
|
|
import ( |
|
"encoding/base64" |
|
"errors" |
|
"github.com/bytedance/sonic" |
|
"sonet/pkg/utils/security" |
|
) |
|
|
|
type Subject struct { |
|
Uid string `json:"uid,omitempty"` |
|
Username string `json:"username,omitempty"` |
|
Time int64 `json:"time,omitempty"` // ms |
|
Extra map[string]string `json:"extra,omitempty"` |
|
} |
|
|
|
// Verify AuthServer Verify logic |
|
func Verify(aesKey []byte, token string) (subject *Subject, err error) { |
|
bytes, err := base64.URLEncoding.DecodeString(token) |
|
if err != nil { |
|
err = errors.New("token decode fail: " + err.Error()) |
|
return |
|
} |
|
decode, err := security.DecryptAesCBC(bytes, aesKey) |
|
if err != nil { |
|
err = errors.New("invalidate token: " + err.Error()) |
|
return |
|
} |
|
subject = &Subject{} |
|
err = sonic.Unmarshal(decode, subject) |
|
if err != nil { |
|
err = errors.New("token payload decode fail: " + err.Error()) |
|
return |
|
} |
|
return |
|
}
|
|
|