PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` */ namespace OCA\OAuth2; require_once __DIR__ . '/../vendor/autoload.php'; use Rowbot\URL\Exception\TypeError; use Rowbot\URL\URL; class Utilities { /** * Generates a random string with 64 characters. * * @return string The random string. */ public static function generateRandom(): string { return \OC::$server->getSecureRandom()->generate( 64, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ); } /** * Validates a redirection URI. * * @param string $expected The expected redirection URI. * @param string $actual The actual redirection URI. * @param boolean $allowSubdomains Whether to allow subdomains. * * @return boolean True if the redirection URI is valid, false otherwise. */ public static function validateRedirectUri($expected, $actual, $allowSubdomains) { $validatePort = true; if (\strpos($expected, 'http://localhost:*') === 0) { $expected = 'http://localhost' . \substr($expected, 18); $validatePort = false; } try { $expectedUrl = new URL($expected); $actualUrl = new URL($actual); if (\strcmp($expectedUrl->protocol, $actualUrl->protocol) !== 0) { return false; } if ($allowSubdomains) { if (\strcmp($expectedUrl->hostname, $actualUrl->hostname) !== 0 && \strcmp($expectedUrl->hostname, \str_replace(\explode('.', $actualUrl->hostname)[0] . '.', '', $actualUrl->hostname)) !== 0 ) { return false; } } elseif (\strcmp($expectedUrl->hostname, $actualUrl->hostname) !== 0) { return false; } if ($validatePort && $expectedUrl->port !== $actualUrl->port) { return false; } if ($expectedUrl->pathname !== $actualUrl->pathname) { return false; } if ($expectedUrl->search !== $actualUrl->search) { return false; } return true; } catch (TypeError $ex) { return false; } } public static function removeWildcardPort($redirectUri): string { if (\strpos($redirectUri, 'http://localhost:*') === 0) { $redirectUri = 'http://localhost' . \substr($redirectUri, 18); } return $redirectUri; } public static function isValidUrl($redirectUri): bool { $redirectUri = Utilities::removeWildcardPort($redirectUri); return (\filter_var($redirectUri, FILTER_VALIDATE_URL) !== false); } // See https://tools.ietf.org/pdf/rfc7636.pdf#56 public static function base64url_encode($data) { return \rtrim(\strtr(\base64_encode($data), '+/', '-_'), '='); } }