Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused headers from validate token routes #422

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions server/action/organisation/application/space/token/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@ import (
"encoding/json"
"errors"
"net/http"
"strconv"

"github.com/factly/kavach-server/model"
"github.com/factly/x/errorx"
"github.com/factly/x/loggerx"
"github.com/factly/x/renderx"
"github.com/factly/x/validationx"
"github.com/go-chi/chi"
)



func Validate(w http.ResponseWriter, r *http.Request) {
sID := chi.URLParam(r, "space_id")
spaceID, err := strconv.Atoi(sID)
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.InvalidID()))
return
}

tokenBody := model.ValidationBody{}
err = json.NewDecoder(r.Body).Decode(&tokenBody)
err := json.NewDecoder(r.Body).Decode(&tokenBody)
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.DecodeError()))
Expand All @@ -50,10 +39,5 @@ func Validate(w http.ResponseWriter, r *http.Request) {
return
}

if spaceToken.SpaceID != uint(spaceID) {
renderx.JSON(w, http.StatusUnauthorized, map[string]interface{}{"valid": false})
return
}

renderx.JSON(w, http.StatusOK, map[string]interface{}{"valid": true})
}
17 changes: 3 additions & 14 deletions server/action/organisation/application/token/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"encoding/json"
"errors"
"net/http"
"strconv"

"github.com/factly/kavach-server/model"
"github.com/factly/x/errorx"
"github.com/factly/x/loggerx"
"github.com/factly/x/renderx"
"github.com/factly/x/validationx"
"github.com/go-chi/chi"
"gorm.io/gorm"
)

Expand All @@ -32,20 +30,10 @@ type validationBody struct {
// @Success 200 {object} model.Application
// @Router /applications/{application_id}/tokens/validate [post]
func validate(w http.ResponseWriter, r *http.Request) {
applicaion_id := chi.URLParam(r, "application_id")
// if applicaion_id == "" {
// errorx.Render(w, errorx.Parser(errorx.GetMessage("invalid id", http.StatusBadRequest)))
// return
// }
id, err := strconv.ParseUint(applicaion_id, 10, 64)
if err != nil {
errorx.Render(w, errorx.Parser(errorx.GetMessage("invalid id", http.StatusBadRequest)))
return
}
//parse applicaion_id

tokenBody := validationBody{}
err = json.NewDecoder(r.Body).Decode(&tokenBody)
err := json.NewDecoder(r.Body).Decode(&tokenBody)
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.DecodeError()))
Expand All @@ -61,8 +49,9 @@ func validate(w http.ResponseWriter, r *http.Request) {

appToken := model.ApplicationToken{}
// Fetch all tokens for a application
// to need to specify the organisation id as token itself is unique
err = model.DB.Model(&model.ApplicationToken{}).Preload("Application").Where(&model.ApplicationToken{
Token: tokenBody.Token, ApplicationID: uint(id),
Token: tokenBody.Token,
}).First(&appToken).Error

if err != nil {
Expand Down
18 changes: 3 additions & 15 deletions server/action/organisation/token/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"encoding/json"
"errors"
"net/http"
"strconv"

"github.com/factly/kavach-server/model"
"github.com/factly/x/errorx"
"github.com/factly/x/loggerx"
"github.com/factly/x/renderx"
"github.com/factly/x/validationx"
"github.com/go-chi/chi"
"gorm.io/gorm"
)

Expand All @@ -32,20 +30,10 @@ type validationBody struct {
// @Success 200 {object} model.organisation
// @Router /organisations/{application_id}/tokens/validate [post]
func validate(w http.ResponseWriter, r *http.Request) {
organisation_id := chi.URLParam(r, "organisation_id")
if organisation_id == "" {
errorx.Render(w, errorx.Parser(errorx.GetMessage("invalid id", http.StatusBadRequest)))
return
}
id, err := strconv.ParseUint(organisation_id, 10, 64)
if err != nil {
errorx.Render(w, errorx.Parser(errorx.GetMessage("invalid id", http.StatusBadRequest)))
return
}
//parse applicaion_id

tokenBody := validationBody{}
err = json.NewDecoder(r.Body).Decode(&tokenBody)
err := json.NewDecoder(r.Body).Decode(&tokenBody)
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.DecodeError()))
Expand All @@ -60,9 +48,9 @@ func validate(w http.ResponseWriter, r *http.Request) {
}

orgToken := model.OrganisationToken{}
// Fetch all tokens for a organisation
// to need to specify the organisation id as token itself is unique
err = model.DB.Model(&model.OrganisationToken{}).Preload("Organisation").Where(&model.OrganisationToken{
Token: tokenBody.Token, OrganisationID: uint(id),
Token: tokenBody.Token,
}).First(&orgToken).Error

if err != nil {
Expand Down
Loading