Skip to content

Commit

Permalink
App Passwords: Don't prevent non-unique App Password names.
Browse files Browse the repository at this point in the history
In [50030] we enforced that Application Passwords have unique names. This was done with the assumption that applications would not connect to a user multiple times. However, in practice we've seen applications run into issues with the unique name constraint. Depending on the app, they may not know if they've been authorized before, or they may intentionally allow connecting multiple times. To prevent friction, App developers need to make their App Name unique, and in doing so often include things like the current date & time, which is already included in the App Passwords list table.

This commit removes this requirement to simplify usage of the Authorize Application flow.

Props mark-k, Boniu91.
Fixes #54213.
  • Loading branch information
TimothyBJacobs committed Sep 17, 2024
1 parent 8f6ec89 commit 7a98ba3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/wp-includes/class-wp-application-passwords.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public static function create_new_application_password( $user_id, $args = array(
return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) );
}

if ( self::application_name_exists_for_user( $user_id, $args['name'] ) ) {
return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) );
}

$new_password = wp_generate_password( static::PW_LENGTH, false );
$hashed_password = wp_hash_password( $new_password );

Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/tests/rest-api/application-passwords.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,14 @@ public function data_update_application_password() {
),
);
}

/**
* @ticket 51941
*/
public function test_can_create_duplicate_app_password_names() {
$created = WP_Application_Passwords::create_new_application_password( self::$user_id, array( 'name' => 'My App' ) );
$this->assertNotWPError( $created );
$created = WP_Application_Passwords::create_new_application_password( self::$user_id, array( 'name' => 'My App' ) );
$this->assertNotWPError( $created );
}
}

0 comments on commit 7a98ba3

Please sign in to comment.