Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Sep 5, 2024
1 parent 87871a1 commit a2d1721
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/LaravelHttpOAuthHelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function boot(): void
array $options = [],
string $tokenType = 'Bearer'
): PendingRequest {

$cacheKey = 'oauth_token_'.str($refreshUrl)->replace(['https://', '/'], [''])->__toString();

$accessToken = Cache::get($cacheKey) ?? app(RefreshToken::class)($cacheKey, ...func_get_args());
Expand Down
2 changes: 1 addition & 1 deletion src/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __invoke(
match ($options['auth_type']) {
'basic' => $httpClient->withBasicAuth($clientId, $clientSecret),
'body' => $requestBody = $requestBody + ['client_id' => $clientId, 'client_secret' => $clientSecret],
'custom' => $httpClient = $options['apply_auth_token']($httpClient),
'custom' => $httpClient = $options['apply_auth_token']($httpClient),
default => throw new Exception('Invalid auth type')
};

Expand Down
25 changes: 13 additions & 12 deletions tests/RefreshTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function testRefreshTokenBasic(): void
$this->assertEquals('this_is_my_access_token', $accessToken);
Http::assertSent(static function (Request $request) {
return $request->hasHeader('Authorization', 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=')
&& $request->url() === 'https://example.com/oauth/token'
&& $request->url() === 'https://example.com/oauth/token'
&& $request['grant_type'] === 'client_credentials'
&& $request['scope'] === 'scope1 scope2';
&& $request['scope'] === 'scope1 scope2';
});
}

Expand All @@ -50,13 +50,14 @@ public function testRefreshTokenBody(): void

$this->assertEquals('this_is_my_access_token', $accessToken);
Http::assertSent(static function (Request $request) {
return $request->url() === 'https://example.com/oauth/token'
&& $request['grant_type'] === 'password_credentials'
&& $request['scope'] === 'scope1 scope2'
&& $request['client_id'] === 'my_client_id'
return $request->url() === 'https://example.com/oauth/token'
&& $request['grant_type'] === 'password_credentials'
&& $request['scope'] === 'scope1 scope2'
&& $request['client_id'] === 'my_client_id'
&& $request['client_secret'] === 'my_client_secret';
});
}

public function testRefreshTokenCustom(): void
{
Cache::clear();
Expand All @@ -67,7 +68,7 @@ public function testRefreshTokenCustom(): void
'grant_type' => 'password_credentials',
'scopes' => ['scope1', 'scope2'],
'auth_type' => 'custom',
'apply_auth_token' => fn(PendingRequest $httpClient) => $httpClient->withHeader('Authorization', 'my_custom_token'),
'apply_auth_token' => fn (PendingRequest $httpClient) => $httpClient->withHeader('Authorization', 'my_custom_token'),
]
);

Expand All @@ -76,7 +77,7 @@ public function testRefreshTokenCustom(): void
return $request->url() === 'https://example.com/oauth/token'
&& $request->hasHeader('Authorization', 'my_custom_token')
&& $request['grant_type'] === 'password_credentials'
&& $request['scope'] === 'scope1 scope2';
&& $request['scope'] === 'scope1 scope2';
});
}

Expand All @@ -97,9 +98,9 @@ public function testRefreshTokenWithExpiry()

$this->assertEquals('this_is_my_access_token', $accessToken);
Http::assertSent(static function (Request $request) {
return $request->url() === 'https://example.com/oauth/token'
return $request->url() === 'https://example.com/oauth/token'
&& $request['grant_type'] === 'client_credentials'
&& $request['scope'] === 'scope1 scope2';
&& $request['scope'] === 'scope1 scope2';
});

Cache::shouldHaveReceived('put')->once()->with('oauth_token_my_token', 'this_is_my_access_token', 60);
Expand Down Expand Up @@ -159,9 +160,9 @@ public function testGetAccessTokenFromCustomKey()
$this->assertEquals('my_custom_access_token', $accessToken);

Http::assertSent(static function (Request $request) {
return $request->url() === 'https://example.com/oauth/token'
return $request->url() === 'https://example.com/oauth/token'
&& $request['grant_type'] === 'client_credentials'
&& $request['scope'] === 'scope1 scope2';
&& $request['scope'] === 'scope1 scope2';
});

Cache::shouldHaveReceived('put')->once()->with('oauth_token_my_token', 'my_custom_access_token', 3600);
Expand Down

0 comments on commit a2d1721

Please sign in to comment.