Skip to content

Commit 3a7d61f

Browse files
added method in OAuth for checking redirect url
1 parent 234fd6b commit 3a7d61f

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
+------------------------------------------------------------------------+
5+
| Phosphorum |
6+
+------------------------------------------------------------------------+
7+
| Copyright (c) 2013-2017 Phalcon Team and contributors |
8+
+------------------------------------------------------------------------+
9+
| This source file is subject to the New BSD License that is bundled |
10+
| with this package in the file LICENSE.txt. |
11+
| |
12+
| If you did not receive a copy of the license and are unable to |
13+
| obtain it through the world-wide-web, please send an email |
14+
| to license@phalconphp.com so we can send you a copy immediately. |
15+
+------------------------------------------------------------------------+
16+
*/
17+
18+
namespace Phosphorum\Exception;
19+
20+
class UrlException extends \LogicException
21+
{
22+
}

app/library/Github/OAuth.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Phalcon\Config;
2222
use Phalcon\Di\Injectable;
2323
use Guzzle\Http\Client as HttpClient;
24+
use Phosphorum\Exception\UrlException;
2425

2526
/**
2627
* Class OAuth
@@ -46,10 +47,12 @@ class OAuth extends Injectable
4647
*/
4748
public function __construct(Config $config)
4849
{
50+
$this->logger = $this->getDI()->get('logger', ['auth']);
51+
$this->checkRedirectGitPath($config->get('redirectUri'));
52+
4953
$this->redirectUriAuthorize = $config->get('redirectUri');
5054
$this->clientId = $config->get('clientId');
5155
$this->clientSecret = $config->get('clientSecret');
52-
$this->logger = $this->getDI()->get('logger', ['auth']);
5356
}
5457

5558
public function authorize()
@@ -132,4 +135,30 @@ public function send($url, $parameters, $method = 'post')
132135
return false;
133136
}
134137
}
138+
139+
/**
140+
* @param string $url
141+
*
142+
*/
143+
protected function checkRedirectGitPath($url)
144+
{
145+
if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED |
146+
FILTER_FLAG_PATH_REQUIRED)) {
147+
throw new UrlException("current URL '{$url}' isn't valid.");
148+
}
149+
150+
if (stristr($url, '://', true) != $this->request->getScheme()) {
151+
$errorMessage = 'HyperText Protocol in your application and in your setting file are different. ';
152+
$errorMessage .= 'Please, check setting in your config file and on Github.';
153+
154+
$this->logger->error($errorMessage);
155+
}
156+
157+
if (substr($url, -1) != '/') {
158+
$errorMessage = 'Authorization callback URL should contain slash in the end. ';
159+
$errorMessage .= 'Please, check setting in your config file and on Github.';
160+
161+
$this->logger->error($errorMessage);
162+
}
163+
}
135164
}

0 commit comments

Comments
 (0)