From 6bab5f129f1c85e1ac81c465366cfb9073480d09 Mon Sep 17 00:00:00 2001 From: Erhan Yakut Date: Mon, 15 Jun 2020 22:44:50 +0300 Subject: [PATCH] change SecureKey to TransmissionKey --- internal/api/auth.go | 20 ++++++++++---------- internal/app/auth.go | 2 +- internal/storage/repository.go | 2 +- internal/storage/token/token_repository.go | 12 ++++++------ model/auth.go | 20 ++++++++++---------- model/token.go | 12 ++++++------ 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/internal/api/auth.go b/internal/api/auth.go index a62fe4d..d744717 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -127,14 +127,14 @@ func Signin(s storage.Store) http.HandlerFunc { s.Tokens().Delete(int(user.ID)) //create tokens on db - s.Tokens().Save(int(user.ID), token.AtUUID, token.AccessToken, token.AtExpiresTime, token.SecureKey) + s.Tokens().Save(int(user.ID), token.AtUUID, token.AccessToken, token.AtExpiresTime, token.TransmissionKey) s.Tokens().Save(int(user.ID), token.RtUUID, token.RefreshToken, token.RtExpiresTime, "") authLoginResponse := model.AuthLoginResponse{ - AccessToken: token.AccessToken, - RefreshToken: token.RefreshToken, - SecureKey: token.SecureKey, - UserDTO: model.ToUserDTO(user), + AccessToken: token.AccessToken, + RefreshToken: token.RefreshToken, + TransmissionKey: token.TransmissionKey, + UserDTO: model.ToUserDTO(user), } RespondWithJSON(w, 200, authLoginResponse) @@ -197,14 +197,14 @@ func RefreshToken(s storage.Store) http.HandlerFunc { s.Tokens().Delete(int(userid)) //create tokens on db - s.Tokens().Save(int(userid), newtoken.AtUUID, newtoken.AccessToken, newtoken.AtExpiresTime, newtoken.SecureKey) + s.Tokens().Save(int(userid), newtoken.AtUUID, newtoken.AccessToken, newtoken.AtExpiresTime, newtoken.TransmissionKey) s.Tokens().Save(int(userid), newtoken.RtUUID, newtoken.RefreshToken, newtoken.RtExpiresTime, "") authLoginResponse := model.AuthLoginResponse{ - AccessToken: newtoken.AccessToken, - RefreshToken: newtoken.RefreshToken, - SecureKey: newtoken.SecureKey, - UserDTO: model.ToUserDTO(user), + AccessToken: newtoken.AccessToken, + RefreshToken: newtoken.RefreshToken, + TransmissionKey: newtoken.TransmissionKey, + UserDTO: model.ToUserDTO(user), } RespondWithJSON(w, 200, authLoginResponse) diff --git a/internal/app/auth.go b/internal/app/auth.go index be4a3b0..c8ad9f7 100644 --- a/internal/app/auth.go +++ b/internal/app/auth.go @@ -61,7 +61,7 @@ func CreateToken(user *model.User) (*model.TokenDetailsDTO, error) { return nil, err } - td.SecureKey = GenerateSecureKey(32) + td.TransmissionKey = GenerateSecureKey(32) return td, nil } diff --git a/internal/storage/repository.go b/internal/storage/repository.go index 45ef479..4d9b138 100644 --- a/internal/storage/repository.go +++ b/internal/storage/repository.go @@ -96,7 +96,7 @@ type EmailRepository interface { // TODO: Add explanation to functions in TokenRepository type TokenRepository interface { Any(uuid string) bool - Save(userid int, uuid uuid.UUID, tkn string, expriydate time.Time, secureKey string) + Save(userid int, uuid uuid.UUID, tkn string, expriydate time.Time, transmissionKey string) Delete(userid int) DeleteByUUID(uuid string) Migrate() error diff --git a/internal/storage/token/token_repository.go b/internal/storage/token/token_repository.go index b63bbc6..6dee676 100644 --- a/internal/storage/token/token_repository.go +++ b/internal/storage/token/token_repository.go @@ -30,14 +30,14 @@ func (p *Repository) Any(uuid string) bool { } -func (p *Repository) Save(userid int, uid uuid.UUID, tkn string, expriydate time.Time, secureKey string) { +func (p *Repository) Save(userid int, uid uuid.UUID, tkn string, expriydate time.Time, transmissionKey string) { token := &model.Token{ - UserID: userid, - UUID: uid, - Token: tkn, - ExpiryTime: expriydate, - SecureKey: secureKey, + UserID: userid, + UUID: uid, + Token: tkn, + ExpiryTime: expriydate, + TransmissionKey: transmissionKey, } p.db.Create(token) diff --git a/model/auth.go b/model/auth.go index 6872953..21dad3a 100644 --- a/model/auth.go +++ b/model/auth.go @@ -14,19 +14,19 @@ type AuthLoginDTO struct { //AuthLoginResponse ... type AuthLoginResponse struct { - AccessToken string `json:"access_token"` - RefreshToken string `json:"refresh_token"` - SecureKey string `json:"secure_key"` + AccessToken string `json:"access_token"` + RefreshToken string `json:"refresh_token"` + TransmissionKey string `json:"transmission_key"` *UserDTO } //TokenDetailsDTO ... type TokenDetailsDTO struct { - AccessToken string `json:"access_token"` - RefreshToken string `json:"refresh_token"` - AtExpiresTime time.Time - RtExpiresTime time.Time - AtUUID uuid.UUID - RtUUID uuid.UUID - SecureKey string `json:"secure_key"` + AccessToken string `json:"access_token"` + RefreshToken string `json:"refresh_token"` + AtExpiresTime time.Time + RtExpiresTime time.Time + AtUUID uuid.UUID + RtUUID uuid.UUID + TransmissionKey string `json:"transmission_key"` } diff --git a/model/token.go b/model/token.go index 10ac590..26e3b3f 100644 --- a/model/token.go +++ b/model/token.go @@ -7,10 +7,10 @@ import ( ) type Token struct { - ID int `gorm:"primary_key" json:"id"` - UserID int - UUID uuid.UUID `gorm:"type:uuid;type:varchar(100);"` - Token string `gorm:"type:text;"` - SecureKey string `gorm:"type:text;"` - ExpiryTime time.Time + ID int `gorm:"primary_key" json:"id"` + UserID int + UUID uuid.UUID `gorm:"type:uuid;type:varchar(100);"` + Token string `gorm:"type:text;"` + TransmissionKey string `gorm:"type:text;"` + ExpiryTime time.Time }