MSP-325 add ids return from authentication

This commit is contained in:
DeniskaRediska committed 2021-10-22 11:00:49 +03:00
1 parent 7b5c6165f2
commit ed7a49ef04
3 files changed
+41 -20

No files matched your search

+15 -3
View File
@@ -23,12 +23,24 @@ type userClaims struct {
UserId int64
}
type adminClaims struct {
*jwt.StandardClaims
Id int64
}
type token struct{}
func (t token) Admin(token string) error {
func (t token) Admin(token string) (int64, error) {
secret := config.GetRemote().(*conf.RemoteConfig).TokensSetting.AdminSecret
_, err := t.parse(token, secret, jwt.MapClaims{})
return err
parsed, err := t.parse(token, secret, &adminClaims{StandardClaims: &jwt.StandardClaims{}})
if err != nil {
return 0, err
}
claims, ok := parsed.Claims.(*adminClaims)
if !ok {
return 0, errInvalidToken
}
return claims.Id, nil
}
func (t token) Application(token string) (int32, error) {