api/auth.go
func removeKeyFromUser(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	key := repository.Key{
		Name: r.URL.Query().Get(":key"),
	}
	if key.Name == "" {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: "Either the content or the name of the key must be provided"}
	}
	allowed := permission.Check(t, permission.PermUserUpdateKeyRemove,
		permission.Context(permTypes.CtxUser, t.GetUserName()),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     userTarget(t.GetUserName()),
		Kind:       permission.PermUserUpdateKeyRemove,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermUserReadEvents, permission.Context(permTypes.CtxUser, t.GetUserName())),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	u, err := auth.ConvertNewUser(t.User())
	if err != nil {
		return err
	}
	err = u.RemoveKey(key)
	if err == authTypes.ErrKeyDisabled {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	if err == repository.ErrKeyNotFound {
		return &errors.HTTP{Code: http.StatusNotFound, Message: "User does not have this key"}
	}
	return err
}
func removeKeyFromUser(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	key := repository.Key{
		Name: r.URL.Query().Get(":key"),
	}
	if key.Name == "" {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: "Either the content or the name of the key must be provided"}
	}
	allowed := permission.Check(t, permission.PermUserUpdateKeyRemove,
		permission.Context(permTypes.CtxUser, t.GetUserName()),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     userTarget(t.GetUserName()),
		Kind:       permission.PermUserUpdateKeyRemove,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermUserReadEvents, permission.Context(permTypes.CtxUser, t.GetUserName())),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	u, err := auth.ConvertNewUser(t.User())
	if err != nil {
		return err
	}
	err = u.RemoveKey(key)
	if err == authTypes.ErrKeyDisabled {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	if err == repository.ErrKeyNotFound {
		return &errors.HTTP{Code: http.StatusNotFound, Message: "User does not have this key"}
	}
	return err
}
// title: remove key
// path: /users/keys/{key}
// method: DELETE
// responses:
//   200: Ok
//   400: Invalid data
//   401: Unauthorized
//   404: Not found