@@ -100,8 +100,8 @@ func (service *auth) CreateToken(w http.ResponseWriter, r *http.Request) {
100
100
101
101
// Check for a valid name
102
102
req .Name = strings .TrimSpace (req .Name )
103
- if req .Name == "" {
104
- httpresponse .Error (w , http .StatusBadRequest , "missing 'name'" )
103
+ if ! types . IsIdentifier ( req .Name ) {
104
+ httpresponse .Error (w , http .StatusBadRequest , "invalid 'name'" )
105
105
return
106
106
} else if token := service .jar .GetWithName (req .Name ); ! token .IsZero () {
107
107
httpresponse .Error (w , http .StatusConflict , "duplicate 'name'" )
@@ -111,6 +111,7 @@ func (service *auth) CreateToken(w http.ResponseWriter, r *http.Request) {
111
111
duration = duration .Truncate (time .Minute )
112
112
if duration < time .Minute {
113
113
httpresponse .Error (w , http .StatusBadRequest , "invalid 'duration'" )
114
+ return
114
115
} else {
115
116
req .Duration .Duration = duration
116
117
}
@@ -123,7 +124,7 @@ func (service *auth) CreateToken(w http.ResponseWriter, r *http.Request) {
123
124
return
124
125
}
125
126
126
- // Add the token
127
+ // Add the token to the jar
127
128
if err := service .jar .Create (token ); err != nil {
128
129
httpresponse .Error (w , http .StatusInternalServerError , err .Error ())
129
130
return
0 commit comments