Skip to main content

token:create

Creates a new authentication token for a user directly from the CLI, without going through an HTTP login request - useful for scripting, seeding test accounts, or bootstrapping access when no token exists yet.

Both arguments are required: identifier is the user’s unique identifier (typically their email, depending on the instance’s configured unique identifier field) or the user’s UUID directly, and password is that user’s plaintext password. The command looks up the user, verifies the password against the stored hash, and on success prints a newly generated token.

The option --capability limits the token to the given capability and can be repeated. The wildcard * is refused, and so are capabilities which the user does not hold.

The command exits with a failure status (without creating a token) if the identifier can’t be resolved to exactly one user, if the user has no password set, or if the password doesn’t match.

Help

php bin/console token:create --help
Description:
  Creates a new token for an user.

Usage:
  token:create [options] [--] <identifier> <password>

Arguments:
  identifier                   Unique identifier of the user (email) or the user's UUID
  password                     Password of the user

Options:
      --capability=CAPABILITY  Capability of the token, e.g. index.manage; can be given multiple times. Tokens have no capabilities by default, the wildcard * can not be requested, and the user must hold the capabilities (multiple values allowed)
  -h, --help                   Display help for the given command. When no command is given display help for the list command
      --silent                 Do not output any message
  -q, --quiet                  Only errors are displayed. All other output is suppressed
  -V, --version                Display this application version
      --ansi|--no-ansi         Force (or disable --no-ansi) ANSI output
  -n, --no-interaction         Do not ask any interactive question
  -e, --env=ENV                The Environment name. [default: "prod"]
      --no-debug               Switch off debug mode.
      --profile                Enables profiling (requires debug).
  -v|vv|vvv, --verbose         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Example

php bin/console token:create token-create-test@localhost.dev 1234
    ▄
  ▄▀ ▀▄  Ember Nexus API
   ▀█▀   v0.3.0, production mode

  Token Create

  Found user with identifier 'token-create-test@localhost.dev', user's UUID is 02IiNr0GPQP1OM96n1dMKZ8GYE39JVk8u5PCb.

▶ Successfully created new token: secret-token:TWhjdYdhOQn1RHPLaRrnBn .