You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/libs/token/user.go

29 lines
644 B
Go

package token
import (
"github.com/veypi/OneAuth/models"
"github.com/veypi/OneAuth/oalib"
"github.com/veypi/utils/jwt"
)
func GetToken(u *models.User, uuid string, key string) (string, error) {
payload := &oalib.PayLoad{
ID: u.ID,
Auth: []*oalib.SimpleAuth{},
}
for _, a := range u.GetAuths() {
if uuid == a.AppUUID {
payload.Auth = append(payload.Auth, &oalib.SimpleAuth{
RID: a.RID,
RUID: a.RUID,
Level: a.Level,
})
}
}
return jwt.GetToken(payload, []byte(key))
}
func ParseToken(token string, payload *oalib.PayLoad, key string) (bool, error) {
return jwt.ParseToken(token, payload, []byte(key))
}