func tokenCreate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var args authTypes.TeamTokenCreateArgs
	err = ParseInput(r, &args)
	if err != nil {
		return err
	}
	if args.Team == "" {
		args.Team, err = autoTeamOwner(t, permission.PermTeamTokenCreate)
		if err != nil {
			return err
		}
	}
	allowed := permission.Check(t, permission.PermTeamTokenCreate,
		permission.Context(permTypes.CtxTeam, args.Team),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     teamTarget(args.Team),
		Kind:       permission.PermTeamTokenCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermTeamReadEvents, permission.Context(permTypes.CtxTeam, args.Team)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	token, err := servicemanager.TeamToken.Create(args, t)
	if err != nil {
		return err
	}
	if err != nil {
		if err == authTypes.ErrTeamTokenAlreadyExists {
			return &errors.HTTP{
				Code:    http.StatusConflict,
				Message: err.Error(),
			}
		}
		return err
	}
	w.WriteHeader(http.StatusCreated)
	return json.NewEncoder(w).Encode(token)
}
func tokenCreate(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var args authTypes.TeamTokenCreateArgs
	err = ParseInput(r, &args)
	if err != nil {
		return err
	}
	if args.Team == "" {
		args.Team, err = autoTeamOwner(t, permission.PermTeamTokenCreate)
		if err != nil {
			return err
		}
	}
	allowed := permission.Check(t, permission.PermTeamTokenCreate,
		permission.Context(permTypes.CtxTeam, args.Team),
	)
	if !allowed {
		return permission.ErrUnauthorized
	}
	evt, err := event.New(&event.Opts{
		Target:     teamTarget(args.Team),
		Kind:       permission.PermTeamTokenCreate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed:    event.Allowed(permission.PermTeamReadEvents, permission.Context(permTypes.CtxTeam, args.Team)),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	token, err := servicemanager.TeamToken.Create(args, t)
	if err != nil {
		return err
	}
	if err != nil {
		if err == authTypes.ErrTeamTokenAlreadyExists {
			return &errors.HTTP{
				Code:    http.StatusConflict,
				Message: err.Error(),
			}
		}
		return err
	}
	w.WriteHeader(http.StatusCreated)
	return json.NewEncoder(w).Encode(token)
}
// title: token create
// path: /tokens
// method: POST
// produce: application/json
// responses:
//   201: Token created
//   401: Unauthorized
//   409: Token already exists