Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/library/Exception/InvalidCalbackUrlException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
+------------------------------------------------------------------------+
| Phosphorum |
+------------------------------------------------------------------------+
| Copyright (c) 2013-2017 Phalcon Team and contributors |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
*/

namespace Phosphorum\Exception;

class InvalidCalbackUrlException extends \LogicException
{
}
32 changes: 31 additions & 1 deletion app/library/Github/OAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Phalcon\Config;
use Phalcon\Di\Injectable;
use Guzzle\Http\Client as HttpClient;
use Phosphorum\Exception\UrlException;

/**
* Class OAuth
Expand All @@ -46,10 +47,12 @@ class OAuth extends Injectable
*/
public function __construct(Config $config)
{
$this->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()
Expand Down Expand Up @@ -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);
}
}
}