private static function normalizeRedirectUriOrigin($redirectUri)
{
$scheme = strtolower(parse_url($redirectUri, PHP_URL_SCHEME));
$host = strtolower(parse_url($redirectUri, PHP_URL_HOST));
$port = parse_url($redirectUri, PHP_URL_PORT);
$usePort = false;
if (null !== $port) {
if (443 !== $port && 'https' === $scheme) {
$usePort = true;
}
if (80 !== $port && 'http' === $scheme) {
$usePort = true;
}
}
if ($usePort) {
return sprintf('%s://%s:%d', $scheme, $host, $port);
}
return sprintf('%s://%s', $scheme, $host);
}