diff --git a/app/library/Exception/InvalidCalbackUrlException.php b/app/library/Exception/InvalidCalbackUrlException.php new file mode 100644 index 00000000..853184ce --- /dev/null +++ b/app/library/Exception/InvalidCalbackUrlException.php @@ -0,0 +1,22 @@ +logger = $this->getDI()->get('logger', ['auth']); + $this->checkRedirectGitPath($config->get('redirectUri')); + $this->redirectUriAuthorize = $config->get('redirectUri'); $this->clientId = $config->get('clientId'); $this->clientSecret = $config->get('clientSecret'); - $this->logger = $this->getDI()->get('logger', ['auth']); } public function authorize() @@ -132,4 +135,31 @@ public function send($url, $parameters, $method = 'post') return false; } } + + /** + * @param string $url + * + */ + protected function checkRedirectGitPath($url) + { + $validationFlags = FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_PATH_REQUIRED; + + if (!filter_var($url, $validationFlags)) { + throw new UrlException("current URL '{$url}' isn't valid."); + } + + if (stristr($url, '://', true) != $this->request->getScheme()) { + $errorMessage = 'The same protocol should be used for the authorization callback URL and forum settings. '; + $errorMessage .= 'Please, check setting in your config file and on Github.'; + + $this->logger->error($errorMessage); + } + + if (substr($url, -1) != '/') { + $errorMessage = 'Authorization callback URL should contain slash in the end. '; + $errorMessage .= 'Please, check setting in your config file and on Github.'; + + $this->logger->error($errorMessage); + } + } }