Skip to content

Commit

Permalink
Merge pull request #473 from mercadopago/fix/oauth-client
Browse files Browse the repository at this point in the history
Fix OAuth client
  • Loading branch information
rhames07 authored Oct 2, 2023
2 parents b8562f8 + c7222bf commit 804e6df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/MercadoPago/Client/OAuth/OAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public function __construct()
* @param string $redirect_uri redirect uri.
* @return string authorization url.
*/
public function getAuthorizationURL(string $app_id, string $redirect_uri): string
public function getAuthorizationURL(string $app_id, string $redirect_uri, string $random_id): string
{
$query_params = [
"client_id" => $app_id,
"response_type" => "code",
"platform_id" => "mp",
"state" => $random_id,
"redirect_uri" => $redirect_uri
];

Expand Down
6 changes: 0 additions & 6 deletions src/MercadoPago/Client/OAuth/OAuthRefreshRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@ class OAuthRefreshRequest

/** Refresh token. */
public string $refresh_token;

/** Code. */
public string $code;

/** Redirect URI. */
public string $redirect_uri;
}
12 changes: 9 additions & 3 deletions tests/MercadoPago/Client/Unit/OAuth/OAuthClientUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
*/
final class OAuthClientUnitTest extends BaseClient
{
public function testGetAuthorizationURLSuccess(): void
{
$client = new OAuthClient();
$url = $client->getAuthorizationURL("app_id", "redirect_uri", "random_id");
$expected = "https://auth.mercadopago.com?client_id=app_id&response_type=code&platform_id=mp&state=random_id&redirect_uri=redirect_uri";
$this->assertSame($expected, $url);
}

public function testCreateSuccess(): void
{
$filepath = '../../../../Resources/Mocks/Response/OAuth/oauth_base.json';
Expand Down Expand Up @@ -44,7 +52,7 @@ public function testRefreshSuccess(): void
MercadoPagoConfig::setHttpClient($http_client);

$client = new OAuthClient();
$oauth = $client->create($this->createRequest());
$oauth = $client->refresh($this->refreshRequest());
$this->assertSame(200, $oauth->getResponse()->getStatusCode());
$this->assertSame("APP_USR-367604750109681-091211-fbad3ab32ad4f89bf1c385141ba5626a-1160535239", $oauth->access_token);
$this->assertSame("Bearer", $oauth->token_type);
Expand All @@ -71,9 +79,7 @@ private function refreshRequest(): OAuthRefreshRequest
$request = new OAuthRefreshRequest();
$request->client_secret = "CLIENT_SECRET";
$request->client_id = "CLIENT_ID";
$request->code = "CODE";
$request->refresh_token = "REFRESH_TOKEN";
$request->redirect_uri = "REDIRECT_URI";
return $request;
}
}

0 comments on commit 804e6df

Please sign in to comment.