PayPal\Api\OpenIdSession::getLogoutUrl PHP Method

getLogoutUrl() public static method

Returns the URL to which the user must be redirected to logout from the OpenID provider (i.e. PayPal)
public static getLogoutUrl ( string $redirectUri, string $idToken, ApiContext $apiContext = null ) : string
$redirectUri string Uri on merchant website to where the user must be redirected to post logout
$idToken string id_token from the TokenInfo object
$apiContext PayPal\Rest\ApiContext Optional API Context
return string logout URL
    public static function getLogoutUrl($redirectUri, $idToken, $apiContext = null)
    {
        if (is_null($apiContext)) {
            $apiContext = new ApiContext();
        }
        $config = $apiContext->getConfig();
        $params = array('id_token' => $idToken, 'redirect_uri' => $redirectUri, 'logout' => 'true');
        return sprintf("%s/webapps/auth/protocol/openidconnect/v1/endsession?%s", self::getBaseUrl($config), http_build_query($params));
    }

Usage Example

 /**
  * @test
  */
 public function testLogoutWithCustomConfig()
 {
     $redirectUri = 'http://mywebsite.com';
     $idToken = 'abc';
     $expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/endsession";
     $this->assertEquals($expectedBaseUrl . "?id_token={$idToken}&redirect_uri=" . urlencode($redirectUri) . "&logout=true", OpenIdSession::getLogoutUrl($redirectUri, $idToken, $this->context), "Failed case - custom config");
 }