Skip to content

Commit

Permalink
Add test for custom token type
Browse files Browse the repository at this point in the history
  • Loading branch information
pelmered committed Sep 16, 2024
1 parent 7e22189 commit 2339f15
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions tests/Unit/RefreshTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
uses(\Pelmered\LaravelHttpOAuthHelper\Tests\TestCase::class);

use Carbon\Carbon;
use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -225,7 +226,7 @@
'my_client_secret',
]),
new Options(
scopes: ['scope1', 'scope2'],
scopes: ['scope1', 'scope2'],
authType: 'invalid',
),
);
Expand All @@ -239,13 +240,12 @@
'https://example.com/oauth/token',
new Credentials(['my_token']),
new Options(
scopes: ['scope1', 'scope2'],
scopes: ['scope1', 'scope2'],
tokenType: AccessToken::TOKEN_TYPE_CUSTOM,
),
);
});


test('access token getters', function () {

$accessToken = app(RefreshToken::class)(
Expand All @@ -262,4 +262,27 @@
->and($accessToken->getCustomCallback())->toBeNull();
});

test('token type custom', function () {

$accessToken = app(RefreshToken::class)(
'https://example.com/oauth/token',
new Credentials(['my_token']),
new Options(
scopes: ['scope1', 'scope2'],
tokenType: AccessToken::TOKEN_TYPE_CUSTOM,
tokenTypeCustomCallback: function (PendingRequest $httpClient) {
return $httpClient->withHeader('MyCustomAuthHeader', 'my_custom_token');
}
),
);

$httpClient = (new Factory)->createPendingRequest();

$httpClient = $accessToken->getHttpClient($httpClient);

$options = $httpClient->getOptions();

expect($options['headers']['MyCustomAuthHeader'])->toBe('my_custom_token');
});

})->done(assignee: 'pelmered');

0 comments on commit 2339f15

Please sign in to comment.