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,31 @@ 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+ $ validationFlags = FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_PATH_REQUIRED ;
146+
147+ if (!filter_var ($ url , $ validationFlags )) {
148+ throw new UrlException ("current URL ' {$ url }' isn't valid. " );
149+ }
150+
151+ if (stristr ($ url , ':// ' , true ) != $ this ->request ->getScheme ()) {
152+ $ errorMessage = 'The same protocol should be used for the authorization callback URL and forum settings. ' ;
153+ $ errorMessage .= 'Please, check setting in your config file and on Github. ' ;
154+
155+ $ this ->logger ->error ($ errorMessage );
156+ }
157+
158+ if (substr ($ url , -1 ) != '/ ' ) {
159+ $ errorMessage = 'Authorization callback URL should contain slash in the end. ' ;
160+ $ errorMessage .= 'Please, check setting in your config file and on Github. ' ;
161+
162+ $ this ->logger ->error ($ errorMessage );
163+ }
164+ }
135165}
0 commit comments