Skip to content

Commit 7a7f098

Browse files
committed
Add test for options
1 parent 518bf12 commit 7a7f098

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Auth0.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,10 @@ public function exchange()
594594
/**
595595
* Renews the access token and ID token using an existing refresh token.
596596
* Scope "offline_access" must be declared in order to obtain refresh token for later token renewal.
597-
*
597+
*
598598
* @param array $options Options for the token endpoint request.
599599
* - options.scope Access token scope requested; optional.
600-
*
600+
*
601601
* @throws CoreException If the Auth0 object does not have access token and refresh token
602602
* @throws ApiException If the Auth0 API did not renew access and ID token properly
603603
* @link https://auth0.com/docs/tokens/refresh-token/current
@@ -612,7 +612,7 @@ public function renewTokens(array $options = [])
612612
throw new CoreException('Can\'t renew the access token if there isn\'t a refresh token available');
613613
}
614614

615-
$response = $this->authentication->refresh_token( $this->refreshToken, $options);
615+
$response = $this->authentication->refresh_token( $this->refreshToken, $options );
616616

617617
if (empty($response['access_token']) || empty($response['id_token'])) {
618618
throw new ApiException('Token did not refresh correctly. Access or ID token not provided.');

tests/Auth0Test.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Firebase\JWT\JWT;
1111
use GuzzleHttp\Handler\MockHandler;
1212
use GuzzleHttp\HandlerStack;
13+
use GuzzleHttp\Middleware;
1314
use GuzzleHttp\Psr7\Response;
1415

1516
/**
@@ -268,28 +269,38 @@ public function testThatRenewTokensFailsIfNoAccessOrIdTokenReturned()
268269
public function testThatRenewTokensSucceeds()
269270
{
270271
$id_token = JWT::encode( ['sub' => uniqid()], '__test_client_secret__' );
271-
272+
$request_history = [];
272273
$mock = new MockHandler( [
273274
// Code exchange response.
274275
new Response( 200, self::$headers, '{"access_token":"1.2.3","refresh_token":"2.3.4"}' ),
275276
// Refresh token response.
276277
new Response( 200, self::$headers, '{"access_token":"__test_access_token__","id_token":"'.$id_token.'"}' ),
277278
] );
279+
$handler = HandlerStack::create($mock);
280+
$handler->push( Middleware::history($request_history) );
278281

279282
$add_config = [
280283
'skip_userinfo' => true,
281284
'persist_access_token' => true,
282-
'guzzle_options' => [ 'handler' => HandlerStack::create($mock) ]
285+
'guzzle_options' => [ 'handler' => $handler ]
283286
];
284287
$auth0 = new Auth0( self::$baseConfig + $add_config );
285288

286289
$_GET['code'] = uniqid();
287290

288291
$this->assertTrue( $auth0->exchange() );
289-
$auth0->renewTokens();
292+
$auth0->renewTokens(['scope' => 'openid']);
290293

291294
$this->assertEquals( '__test_access_token__', $auth0->getAccessToken() );
292295
$this->assertEquals( $id_token, $auth0->getIdToken() );
296+
297+
$renew_request = $request_history[1]['request'];
298+
$renew_body = json_decode($renew_request->getBody(), true);
299+
$this->assertEquals( 'openid', $renew_body['scope'] );
300+
$this->assertEquals( '__test_client_secret__', $renew_body['client_secret'] );
301+
$this->assertEquals( '__test_client_id__', $renew_body['client_id'] );
302+
$this->assertEquals( '2.3.4', $renew_body['refresh_token'] );
303+
$this->assertEquals( 'https://__test_domain__/oauth/token', (string) $renew_request->getUri() );
293304
}
294305

295306
public function testThatGetLoginUrlUsesDefaultValues()

0 commit comments

Comments
 (0)