Skip to content
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
9 changes: 2 additions & 7 deletions ProcessMaker/Mail/MicrosoftGraphTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace ProcessMaker\Mail;

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache;
use RuntimeException;

class MicrosoftGraphTokenProvider
Expand All @@ -15,17 +14,13 @@ class MicrosoftGraphTokenProvider
public function __construct(
private array $config,
private int|string $serverIndex = 0,
private ?Client $httpClient = null
private ?Client $httpClient = null,
) {
}

public function getAccessToken(): string
{
$cacheKey = 'microsoft_graph_access_token_' . ($this->serverIndex ?: 'default');

return Cache::remember($cacheKey, now()->addMinutes(50), function () {
return $this->requestAccessToken();
});
return $this->requestAccessToken();
}

private function requestAccessToken(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Illuminate\Support\Facades\Cache;
use Mockery;
use ProcessMaker\Mail\MicrosoftGraphTokenProvider;
use RuntimeException;
Expand Down Expand Up @@ -34,8 +33,6 @@ public function testGetAccessTokenThrowsWhenCredentialsAreMissing()

public function testGetAccessTokenRequestsTokenFromMicrosoft()
{
Cache::flush();

$tokenResponse = new Response(200, [], json_encode(['access_token' => 'token-from-azure']));

$guzzle = Mockery::mock(Client::class);
Expand All @@ -60,6 +57,5 @@ public function testGetAccessTokenRequestsTokenFromMicrosoft()
], 1, $guzzle);

$this->assertSame('token-from-azure', $provider->getAccessToken());
$this->assertSame('token-from-azure', $provider->getAccessToken());
}
}
Loading