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

Remove the deprecated legacy methods and tests #222

Merged
merged 7 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@ $client->setAccessToken('abc123');
// Set Client credentials if using that grant type
$client->useClientCredentials($appId, $appSecret);

// Use legacy clientId and apiKey
$client->useLegacyToken($clientId, $apiKey);

// Use a refresh token to get a new access token
$client->useRefreshToken($appId, $appSecret, $refreshToken);
```

**Note**
The `legacy_credentials` auth method is provided for developer convenience while both v1 and v2 of the API are active. When v1 of the API sunsets on June 6th, 2019, this auth scheme will no longer be active.

You can also pass auth credentials when you create the client.

Expand All @@ -93,16 +89,6 @@ $config = [
];
$client = ApiClientFactory::createClient($config);

// Using Legacy credentials - deprecated and will be removed on June 6, 2019
$config = [
'auth' => [
'type' => 'legacy_credentials',
'clientId' => 'asdf1234',
'apiKey' => 'fdas4321'
]
];
$client = ApiClientFactory::createClient($config);

// Using a refresh token
$config = [
'auth' => [
Expand Down
12 changes: 0 additions & 12 deletions examples/transition.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@ public function useClientCredentials(string $appId, string $appSecret): ApiClien
return $this;
}

/**
* The Legacy Token auth scheme is provided as a developer convenience
* while transitioning from v1 to v2 of the API. On June 6, 2019, we will
* sunset v1 of the API. At that time, this method will no longer function
* and we will remove it from the SDK.
*
* @deprecated
*/
public function useLegacyToken(string $clientId, string $apiKey): ApiClient
{
$this->getAuthenticator()
->useLegacyToken($clientId, $apiKey);

return $this;
}

public function useRefreshToken(string $appId, string $appSecret, string $refreshToken): ApiClient
{
$this->getAuthenticator()
Expand Down
57 changes: 0 additions & 57 deletions src/Http/Auth/LegacyCredentials.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Http/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use GuzzleHttp\Client;
use HelpScout\Api\Http\Auth\Auth;
use HelpScout\Api\Http\Auth\ClientCredentials;
use HelpScout\Api\Http\Auth\LegacyCredentials;
use HelpScout\Api\Http\Auth\NullCredentials;
use HelpScout\Api\Http\Auth\RefreshCredentials;

Expand Down Expand Up @@ -119,19 +118,6 @@ public function useClientCredentials(string $appId, string $appSecret): void
$this->auth = new ClientCredentials($appId, $appSecret);
}

/**
* The Legacy Token auth scheme is provided as a developer convenience
* while transitioning from v1 to v2 of the API. On June 6, 2019, we will
* sunset v1 of the API. At that time, this method will no longer function
* and we will remove it from the SDK.
*
* @deprecated
*/
public function useLegacyToken(string $clientId, string $apiKey): void
{
$this->auth = new LegacyCredentials($clientId, $apiKey);
}

public function useRefreshToken(string $appId, string $appSecret, string $refreshToken): void
{
$this->auth = new RefreshCredentials($appId, $appSecret, $refreshToken);
Expand All @@ -145,9 +131,6 @@ public function setAuth(Auth $auth): void
protected function fetchTokens(): void
{
switch ($this->auth->getType()) {
case LegacyCredentials::TYPE:
$this->convertLegacyToken();
break;
case ClientCredentials::TYPE:
case RefreshCredentials::TYPE:
$this->fetchAccessAndRefreshToken();
Expand All @@ -171,26 +154,6 @@ public function fetchAccessAndRefreshToken(): self
return $this;
}

/**
* This conversion helper is provided as a developer convenience while
* transitioning from v1 to v2 of the API. On June 6, 2019, we will sunset
* v1 of the API. At that time, this method will no longer function and we
* will remove it from the SDK.
*
* @deprecated
*/
public function convertLegacyToken(): void
{
$tokens = $this->requestAuthTokens(
$this->auth->getPayload(),
self::TRANSITION_URL
);

$this->accessToken = $tokens['accessToken'];
$this->refreshToken = $tokens['refreshToken'];
$this->ttl = $tokens['expiresIn'];
}

private function requestAuthTokens(array $payload, string $url): array
{
$headers = [
Expand Down
6 changes: 0 additions & 6 deletions src/Http/RestClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use GuzzleHttp\Psr7\Response;
use HelpScout\Api\Http\Auth\Auth;
use HelpScout\Api\Http\Auth\ClientCredentials;
use HelpScout\Api\Http\Auth\LegacyCredentials;
use HelpScout\Api\Http\Auth\NullCredentials;
use HelpScout\Api\Http\Auth\RefreshCredentials;
use HelpScout\Api\Http\Handlers\AuthenticationHandler;
Expand Down Expand Up @@ -68,11 +67,6 @@ protected function getAuthClass(array $authConfig = []): Auth
$authConfig['appId'],
$authConfig['appSecret']
);
case LegacyCredentials::TYPE:
return new LegacyCredentials(
$authConfig['clientId'],
$authConfig['apiKey']
);
case RefreshCredentials::TYPE:
return new RefreshCredentials(
$authConfig['appId'],
Expand Down
15 changes: 0 additions & 15 deletions tests/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ public function testUseClientCredentials()
);
}

public function testUseLegacyCredentials()
{
$clientId = 'abc123';
$apiKey = '321cba';

$this->authenticator->shouldReceive('useLegacyToken')
->once()
->with($clientId, $apiKey);
$result = $this->client->useLegacyToken($clientId, $apiKey);
$this->assertSame(
$result,
$this->client
);
}

public function testUseRefreshToken()
{
$appId = 'abc123';
Expand Down
55 changes: 0 additions & 55 deletions tests/Authentication/AuthenticationIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use GuzzleHttp\Client;
use HelpScout\Api\Http\Auth\ClientCredentials;
use HelpScout\Api\Http\Auth\LegacyCredentials;
use HelpScout\Api\Http\Auth\NullCredentials;
use HelpScout\Api\Http\Auth\RefreshCredentials;
use HelpScout\Api\Http\Authenticator;
Expand Down Expand Up @@ -69,22 +68,6 @@ public function testClientCredentialsSetsAuth()
$this->assertSame($expectedPayload, $auth->getPayload());
}

public function testLegacyCredentialsSetsAuth()
{
$clientId = '123abc';
$apiKey = 'fdafda';
$expectedPayload = [
'clientId' => $clientId,
'apiKey' => $apiKey,
];

$this->authenticator->useLegacyToken($clientId, $apiKey);
$auth = $this->authenticator->getAuthCredentials();
$this->assertSame(LegacyCredentials::TYPE, $auth->getType());
$this->assertInstanceOf(LegacyCredentials::class, $auth);
$this->assertSame($expectedPayload, $auth->getPayload());
}

public function testUseRefreshTokenCredentials()
{
$appId = '123abc';
Expand All @@ -103,44 +86,6 @@ public function testUseRefreshTokenCredentials()
$this->assertSame($expectedPayload, $auth->getPayload());
}

public function testAuthenticatorFetchesTokensWithLegacyCredentials()
{
$clientId = '123abc';
$apiKey = 'fdafda';
$auth = new LegacyCredentials($clientId, $apiKey);
$expectedPayload = [
'clientId' => $clientId,
'apiKey' => $apiKey,
];

$expectedOptions = [
'headers' => [
'Content-Type' => 'application/json;charset=UTF-8',
],
'json' => $expectedPayload,
];

$tokenResponse = [
'accessToken' => 'fdsafdas',
'refreshToken' => 'asdfasdf',
'expiresIn' => 7200,
];
$expectedResponse = $this->getResponse(200, json_encode($tokenResponse));

$this->guzzle->shouldReceive('request')
->with('POST', Authenticator::TRANSITION_URL, $expectedOptions)
->andReturn($expectedResponse);

$expectedResult = [
'Authorization' => 'Bearer fdsafdas',
];

$authenticator = new Authenticator(new Client(), $auth);
$authenticator->setClient($this->guzzle);
$result = $authenticator->getAuthHeader();
$this->assertSame($expectedResult, $result);
}

public function testAuthenticatorFetchesTokensWithClientCredentials()
{
$appId = '123abc';
Expand Down
19 changes: 0 additions & 19 deletions tests/Http/RestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use GuzzleHttp\Psr7\Response;
use HelpScout\Api\ApiClient;
use HelpScout\Api\Http\Auth\ClientCredentials;
use HelpScout\Api\Http\Auth\LegacyCredentials;
use HelpScout\Api\Http\Auth\NullCredentials;
use HelpScout\Api\Http\Auth\RefreshCredentials;
use HelpScout\Api\Http\Authenticator;
Expand Down Expand Up @@ -115,24 +114,6 @@ public function testRestClientBuilderHandlesRefreshCredentialsAuth()
);
}

public function testRestClientBuilderHandlesLegacyCredentialsAuth()
{
$config = [
'auth' => [
'type' => LegacyCredentials::TYPE,
'clientId' => '123abc',
'apiKey' => 'cba321',
],
];
$builder = new RestClientBuilder($config);
$client = $builder->build();

$this->assertInstanceOf(
LegacyCredentials::class,
$client->getAuthenticator()->getAuthCredentials()
);
}

public function testRestClientBuilderHandlesNullCredentialsAuth()
{
$config = [];
Expand Down