changed token
This commit is contained in:
1 parent
0c5b23b790
commit
9884712392
6 files changed
+58
-23
No files matched your search
Generated
+9
-1
@@ -25,6 +25,14 @@
|
||||
revision = "ade4e2031af3aed7fffd241084aad80a58faf421"
|
||||
version = "v0.1.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:76dc72490af7174349349838f2fe118996381b31ea83243812a97e5a0fd5ed55"
|
||||
name = "github.com/dgrijalva/jwt-go"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e"
|
||||
version = "v3.2.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd"
|
||||
name = "github.com/fsnotify/fsnotify"
|
||||
@@ -563,13 +571,13 @@
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/dgrijalva/jwt-go",
|
||||
"github.com/go-pg/pg",
|
||||
"github.com/integration-system/isp-lib/backend",
|
||||
"github.com/integration-system/isp-lib/bootstrap",
|
||||
"github.com/integration-system/isp-lib/database",
|
||||
"github.com/integration-system/isp-lib/logger",
|
||||
"github.com/integration-system/isp-lib/metric",
|
||||
"github.com/integration-system/isp-lib/socket",
|
||||
"github.com/integration-system/isp-lib/structure",
|
||||
"github.com/integration-system/isp-lib/token-gen",
|
||||
"github.com/integration-system/isp-lib/utils",
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
)
|
||||
|
||||
type RemoteConfig struct {
|
||||
Database structure.DBConfiguration `valid:"required~Required" json:"database" schema:"Database"`
|
||||
Metrics structure.MetricConfiguration `schema:"Metrics"`
|
||||
Database structure.DBConfiguration `valid:"required~Required" json:"database" schema:"Database"`
|
||||
Metrics structure.MetricConfiguration `schema:"Metrics"`
|
||||
SecretKey string
|
||||
ExpirySec int
|
||||
}
|
||||
+16
-12
@@ -4,7 +4,8 @@ import (
|
||||
"fmt"
|
||||
"github.com/integration-system/isp-lib/logger"
|
||||
libStr "github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/token-gen"
|
||||
"msp-admin-service/token"
|
||||
//"github.com/integration-system/isp-lib/token-gen"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
libUtils "github.com/integration-system/isp-lib/utils"
|
||||
"github.com/integration-system/isp-lib/validate"
|
||||
@@ -24,7 +25,7 @@ func Logout(metadata metadata.MD) error {
|
||||
st := status.New(codes.InvalidArgument, utils.ServiceError)
|
||||
return st.Err()
|
||||
}
|
||||
model.InvalidateOldToken(token[0])
|
||||
//model.InvalidateOldToken(token[0])
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -56,18 +57,21 @@ func Login(authRequest structure.AuthRequest) (*structure.Auth, error) {
|
||||
return nil, status.New(codes.Unauthenticated, "Email or password is incorrect").Err()
|
||||
}
|
||||
|
||||
_, err = model.InvalidateOldTokens(user.Id)
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
}
|
||||
token, err := model.CreateNewToken(user.Id, tg.Default.NextDefault(), nil)
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
}
|
||||
/*
|
||||
_, err = model.InvalidateOldTokens(user.Id)
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
}
|
||||
token, err := model.CreateNewToken(user.Id, tg.Default.NextDefault(), nil)
|
||||
if err != nil {
|
||||
return nil, validate.CreateUnknownError(err)
|
||||
}
|
||||
*/
|
||||
|
||||
tokenString, expired := token.GetToken(string(user.Id))
|
||||
return &structure.Auth{
|
||||
Token: token.Token,
|
||||
Expired: token.ExpiredAt.Format(libUtils.FullDateFormat),
|
||||
Token: tokenString,
|
||||
Expired: expired,
|
||||
HeaderName: utils.ADMIN_AUTH_HEADER_NAME,
|
||||
}, nil
|
||||
}
|
||||
|
||||
+2
-7
@@ -1,12 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/integration-system/isp-lib/database"
|
||||
libStr "github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
const DELETE_TOKENS = "DELETE FROM " + utils.DB_SCHEME + ".tokens WHERE user_id=?"
|
||||
const DELETE_TOKEN = "DELETE FROM " + utils.DB_SCHEME + ".tokens WHERE token=?"
|
||||
|
||||
@@ -32,3 +26,4 @@ func CreateNewToken(userId int64, tokenString string, expiredTime *time.Time) (*
|
||||
Insert()
|
||||
return &token, err
|
||||
}
|
||||
*/
|
||||
+1
-1
@@ -2,7 +2,7 @@ package structure
|
||||
|
||||
type Auth struct {
|
||||
Token string `json:"token"`
|
||||
Expired string `json:"expired"`
|
||||
Expired string `json:"expired,omitempty"`
|
||||
HeaderName string `json:"headerName"`
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/integration-system/isp-lib/config"
|
||||
"msp-admin-service/conf"
|
||||
"time"
|
||||
)
|
||||
|
||||
type customClaims struct {
|
||||
id string
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
func GetToken(id string) (string, string) {
|
||||
expired := ""
|
||||
claims := customClaims{id: id}
|
||||
cfg := config.GetRemote().(*conf.RemoteConfig)
|
||||
if cfg.ExpirySec != 0 {
|
||||
exp := time.Now().Add(time.Second * time.Duration(cfg.ExpirySec))
|
||||
expired = exp.String()
|
||||
claims.ExpiresAt = exp.Unix()
|
||||
}
|
||||
tokenString, _ := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(cfg.SecretKey))
|
||||
return tokenString, expired
|
||||
}
|
||||
Reference in new issue
Block a user