Skip to content

Commit 324d093

Browse files
committed
Endpoint updates
1 parent bed6bd2 commit 324d093

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pkg/handler/auth/endpoints.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,18 @@ func (service *auth) CreateToken(w http.ResponseWriter, r *http.Request) {
103103
req.Name = strings.TrimSpace(req.Name)
104104
if req.Name == "" {
105105
httpresponse.Error(w, http.StatusBadRequest, "missing 'name'")
106-
} else if token := service.jar.GetWithName(req.Name); token.IsValid() {
106+
return
107+
} else if token := service.jar.GetWithName(req.Name); !token.IsZero() {
107108
httpresponse.Error(w, http.StatusConflict, "duplicate 'name'")
109+
return
110+
} else if duration := req.Duration.Duration; duration > 0 {
111+
// Truncate duration to minute, check
112+
duration = duration.Truncate(time.Minute)
113+
if duration < time.Minute {
114+
httpresponse.Error(w, http.StatusBadRequest, "invalid 'duration'")
115+
} else {
116+
req.Duration.Duration = duration
117+
}
108118
}
109119

110120
// Create the token

pkg/handler/auth/scope.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import "github.com/mutablelogic/go-server/pkg/version"
44

55
var (
66
// Root scope allows ANY operation
7-
ScopeRoot = version.GitSource + "scope/root"
7+
ScopeRoot = version.GitSource + "/scope/root"
88
)

0 commit comments

Comments
 (0)