Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added method in OAuth for checking redirect url #392

Open
wants to merge 1 commit into
base: 3.5.x
Choose a base branch
from
Open
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
@@ -21,6 +21,7 @@
use Phalcon\Config;
use Phalcon\Di\Injectable;
use Guzzle\Http\Client as HttpClient;
use Phosphorum\Exception\UrlException;

/**
* Class OAuth
@@ -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()
@@ -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);
}
}
}