Skip to content

Commit

Permalink
Merge pull request #87 from robinvdvleuten/logout-params-fix
Browse files Browse the repository at this point in the history
Correctly build logout url query string
  • Loading branch information
glena committed Jun 21, 2016
2 parents 36e08aa + 21373b8 commit fbc19f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/Auth0AuthApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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 = []){
Expand Down
14 changes: 12 additions & 2 deletions tests/AuthApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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']));
}
}

0 comments on commit fbc19f2

Please sign in to comment.