Skip to content

New command wp (api|json) generate application-password #329

Closed

Description

@pfefferle

Feature Request

Describe your use case and the problem you are facing

A new cli command to handle API commands in general and a command to generate application-passwords in particular.

Describe the solution you'd like

To setup a WordPress blog using the CLI, it would be helpful to also have a command to pre-generate application-passwords.

Activity

  1. changed the title [-]`wp (api|json) generate application-password*`[/-] [+]`wp (api|json) generate application-password`[/+] on Mar 23, 2021
  2. changed the title [-]`wp (api|json) generate application-password`[/-] [+]New command `wp (api|json) generate application-password`[/+] on Mar 23, 2021
  3. swissspidy commented on Mar 23, 2021

    @swissspidy
    Member

    Since app passwords are stored per-user, this would fall under the wp user umbrella (wp-cli/entity-command).

    Since app passwords can be added, listed and revoked, this could result in a new family of wp user sub commands.

    In the meantime, you might be able to use wp eval for this (untested):

    $  wp eval 'WP_Application_Passwords::create_new_application_password( 123, array( "name" => "test" ) )'
  4. pfefferle commented on Mar 23, 2021

    @pfefferle
    Author

    Good point, thanks for your answer @swissspidy !

    Should I move the issue to the entity-command repo?

  5. swissspidy commented on Mar 23, 2021

    @swissspidy
    Member

    We'll transfer it if needed. Can keep it here for discussion :)

  6. DeLm0re commented on Nov 22, 2021

    @DeLm0re

    Are there any news about this suggestion ?

    After reading some documentation, and like @swissspidy said, the only working solution for now is to use the following command :

    $ wp eval 'WP_Application_Passwords::create_new_application_password( 123, array( "name" => "test" ) );'

    Note that the ; is mandatory otherwise it won't work in command line.

    There is still a main issue for me with this solution.
    In order to deploy WordPress websites accessible from my own tier application. I have to store generated password. However, the command above only creates an application password and do not return to you the generated value !
    Plus, it does not seems to accept a given value for the password. (command is running but value is ignored) eg:

    $ wp eval 'WP_Application_Passwords::create_new_application_password( 123, array( "name" => "test", "value" => "8lJB MyXY s3FC ArTF 81Kb QVAe") );'

    In conclusion, it would be very helpful if such a WP CLI command exists:

    wp generate application-password <userId> <name> <password>

    or at least, make possible that eval command output the generated password.
    I do already tried something like :

    $ wp eval '$tmp = WP_Application_Passwords::create_new_application_password( 1, array( "name" => "test" ) ); echo($tmp[1]["password"]."\n");'

    Unfortunately, this method returns the hashed password ... not the real password value.

  7. swissspidy commented on Nov 22, 2021

    @swissspidy
    Member

    I do already tried something like :

    $ wp eval '$tmp = WP_Application_Passwords::create_new_application_password( 1, array( "name" => "test" ) ); echo($tmp[1]["password"]);'

    Unfortunatly, this method returns the hashed password ... not the real password value.

    Check the method's documentation; the unhashed password is the first array item.

    So:

    $ wp eval '$tmp = WP_Application_Passwords::create_new_application_password( 1, array( "name" => "test" ) ); echo($tmp[0]);'

    As for implementing this feature, I believe we are looking for the following commands:

    • wp user application-password list <user>
    • wp user application-password get <user> <uuid>
    • wp user application-password has <user> <name>
    • wp user application-password update <user> <uuid> [--<field>=<value>]
    • wp user application-password record-usage <user> <uuid>
    • wp user application-password create <user> <name> [--app_id=<value>]
  8. DeLm0re commented on Nov 22, 2021

    @DeLm0re

    @swissspidy Oh wow, thanks for the fast reply.

    That is exactly what i'm looking for. Perfect 👍

  9. schlessera commented on Dec 1, 2021

    @schlessera
    Member

    @swissspidy I'm currently working on implementing these new commands and going by what you've suggested above.

    I'm surprised about the need to provide a user ID when retrieving an application password by UUID, which seems to also be a requirement by Core's API. Given a UUID should be unique even across users, I don't really understand the design of the data model... Was that for performance reasons that they are stored in user meta? A new table would have made much more sense (and would have been even more performant)...

  10. transferred this issue fromwp-cli/ideason Dec 1, 2021
  11. swissspidy commented on Dec 5, 2021

    @swissspidy
    Member

    Yeah that is a good question... Core never really adds new tables and perhaps user meta was considered to be a good fit because of the number of expected entries. I'd have to dig up the core trac ticket to get the context though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions