41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package sys
|
|
|
|
import (
|
|
"errors"
|
|
"reflect"
|
|
)
|
|
|
|
var sysKey = "devtoken"
|
|
|
|
// [DEPRECATED] (This has to be redone the token system wont work as intended) might be reused on a differnt point (api access maybe)
|
|
// ValidatePermToken validates a given token against the settings object of a given server
|
|
/* func ValidatePermToken(permtoken string, serverid string) (error, bool) {
|
|
token, err := sys.Client.Settings.Query().Where(settings.Serverid(serverid)).Select(settings.FieldPermtoken).All(sys.Ctx)
|
|
|
|
if err != nil {
|
|
return errors.New("could_not_fetch_token_from_database"), false
|
|
}
|
|
|
|
if token[0].Permtoken == permtoken {
|
|
return nil, true
|
|
}
|
|
|
|
return nil, false
|
|
} */
|
|
|
|
// [deprecated] will be replaced with jwt entierly
|
|
// ValidateAuthToken validates a given token against the settings object of a given server
|
|
// Used to prevent third parties of using unallowed routes
|
|
func ValidateAuthToken(toValidate string) (error, bool) {
|
|
if reflect.TypeOf(toValidate).String() != "string" {
|
|
return errors.New("token given is not of type string"), false
|
|
}
|
|
|
|
// Validate token agains system known token
|
|
if toValidate == sysKey {
|
|
return nil, true
|
|
} else {
|
|
return nil, false
|
|
}
|
|
}
|