diff --git a/src/Auth0AuthApi.php b/src/Auth0AuthApi.php index ee2708e1..68af80a8 100644 --- a/src/Auth0AuthApi.php +++ b/src/Auth0AuthApi.php @@ -5,6 +5,7 @@ use Auth0\SDK\API\Header\ContentType; use Auth0\SDK\API\Helpers\ApiClient; use Auth0\SDK\Exception\ApiException; +use GuzzleHttp\Psr7; class Auth0AuthApi { @@ -55,9 +56,7 @@ public function get_authorize_link($response_type, $redirect_uri, $connection = $aditional_params['state'] = $state; } - $query_string = implode('&', array_map(function($key,$value){ - return "$key=$value"; - }, array_keys($aditional_params), $aditional_params)); + $query_string = Psr7\build_query($aditional_params); return "https://{$this->domain}/authorize?$query_string"; } @@ -95,10 +94,10 @@ public function get_logout_link($returnTo = null, $client_id = null) { if ($client_id !== null) { $params['client_id'] = $client_id; } - $query_string = implode('&', $params); - return "https://{$this->domain}/logout?$query_string"; + $query_string = Psr7\build_query($params); + return "https://{$this->domain}/logout?$query_string"; } public function authorize_with_accesstoken($access_token, $connection, $scope = 'openid', $aditional_params = []){ diff --git a/tests/AuthApiTest.php b/tests/AuthApiTest.php index 9bb90763..4d34972b 100644 --- a/tests/AuthApiTest.php +++ b/tests/AuthApiTest.php @@ -14,11 +14,11 @@ public function testAuthorize() { $authorize_url = $api->get_authorize_link('code', 'http://lala.com'); - $this->assertEquals("https://dummy.auth0.com/authorize?response_type=code&redirect_uri=http://lala.com&client_id=123456", $authorize_url); + $this->assertEquals("https://dummy.auth0.com/authorize?response_type=code&redirect_uri=http%3A%2F%2Flala.com&client_id=123456", $authorize_url); $authorize_url2 = $api->get_authorize_link('token', 'http://lala.com', 'facebook', 'dastate'); - $this->assertEquals("https://dummy.auth0.com/authorize?response_type=token&redirect_uri=http://lala.com&client_id=123456&connection=facebook&state=dastate", $authorize_url2); + $this->assertEquals("https://dummy.auth0.com/authorize?response_type=token&redirect_uri=http%3A%2F%2Flala.com&client_id=123456&connection=facebook&state=dastate", $authorize_url2); } public function testAuthorizeWithRO() { @@ -71,4 +71,14 @@ public function testImpersonation() { $this->assertStringStartsWith("https://" . $env['DOMAIN'], $url); } + + public function testLogoutLink() { + $env = $this->getEnv(); + + $api = new Auth0AuthApi($env['DOMAIN'], $env['GLOBAL_CLIENT_ID'], $env['GLOBAL_CLIENT_SECRET']); + + $this->assertSame("https://" . $env['DOMAIN'] . "/logout?", $api->get_logout_link()); + $this->assertSame("https://" . $env['DOMAIN'] . "/logout?returnTo=http%3A%2F%2Fexample.com", $api->get_logout_link("http://example.com")); + $this->assertSame("https://" . $env['DOMAIN'] . "/logout?returnTo=http%3A%2F%2Fexample.com&client_id=" . $env['GLOBAL_CLIENT_ID'], $api->get_logout_link("http://example.com", $env['GLOBAL_CLIENT_ID'])); + } } \ No newline at end of file