2121use Phalcon \Config ;
2222use Phalcon \Di \Injectable ;
2323use 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