Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename redirect_url to store_url in the state parameter #2396

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/API/WP/OAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,31 @@ class OAuthService implements Service, OptionsAwareInterface {
* scope=wc-partner-access&
* state=URL_SAFE_BASE64_ENCODED_STRING
*
* State is an URL safe base64 encoded string.
* State is a URL safe base64 encoded string.
* E.g.
* state=bm9uY2UtMTIzJnJlZGlyZWN0X3VybD1odHRwcyUzQSUyRiUyRm1lcmNoYW50LXNpdGUuZXhhbXBsZS5jb20lMkZ3cC1hZG1pbiUyRmFkbWluLnBocCUzRnBhZ2UlM0R3Yy1hZG1pbiUyNnBhdGglM0QlMkZnb29nbGUlMkZzZXR1cC1tYw
*
* The decoded content of state is an URL query string where the value of its parameter "redirect_url" is being URL encoded.
* The decoded content of state is a URL query string where the value of its parameter "store_url" is being URL encoded.
* E.g.
* nonce=nonce-123&redirect_url=https%3A%2F%2Fmerchant-site.example.com%2Fwp-admin%2Fadmin.php%3Fpage%3Dwc-admin%26path%3D%2Fgoogle%2Fsetup-mc
* nonce=nonce-123&store_url=https%3A%2F%2Fmerchant-site.example.com%2Fwp-admin%2Fadmin.php%3Fpage%3Dwc-admin%26path%3D%2Fgoogle%2Fsetup-mc
*
* where its URL decoded version is:
* nonce=nonce-123&redirect_url=https://merchant-site.example.com/wp-admin/admin.php?page=wc-admin&path=/google/setup-mc
* nonce=nonce-123&store_url=https://merchant-site.example.com/wp-admin/admin.php?page=wc-admin&path=/google/setup-mc
*
* @param string $path An URL parameter for the path within GL&A page, which will be added in the merchant redirect URL.
* @param string $path A URL parameter for the path within GL&A page, which will be added in the merchant redirect URL.
*
* @return string Auth URL.
*/
public function get_auth_url( string $path ): string {
$google_data = $this->get_data_from_google();

$merchant_redirect_url = urlencode_deep( admin_url( "admin.php?page=wc-admin&path={$path}" ) );
$store_url = urlencode_deep( admin_url( "admin.php?page=wc-admin&path={$path}" ) );

$state = $this->base64url_encode(
build_query(
[
'nonce' => $google_data['nonce'],
'redirect_url' => $merchant_redirect_url,
'nonce' => $google_data['nonce'],
'store_url' => $store_url,
]
)
);
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/API/WP/OAuthServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public function test_get_auth_url() {
]
);

$merchant_redirect_url = "{$admin_url}admin.php?page=wc-admin&path={$path}";
$merchant_redirect_url_encoded = urlencode_deep( $merchant_redirect_url );
$expected_state_raw = "nonce={$nonce}&redirect_url={$merchant_redirect_url_encoded}";
$state = $this->base64url_encode( $expected_state_raw );
$store_url = "{$admin_url}admin.php?page=wc-admin&path={$path}";
$store_url_encoded = urlencode_deep( $store_url );
$expected_state_raw = "nonce={$nonce}&store_url={$store_url_encoded}";
$state = $this->base64url_encode( $expected_state_raw );

$expected_auth_url = 'https://public-api.wordpress.com/oauth2/authorize';
$expected_auth_url .= "?blog={$blog_id}";
Expand Down Expand Up @@ -120,8 +120,8 @@ public function test_get_auth_url() {
$parsed_state['nonce']
);
$this->assertEquals(
$merchant_redirect_url,
$parsed_state['redirect_url']
$store_url,
$parsed_state['store_url']
);
}
}
Loading