21
21
use Phalcon \Config ;
22
22
use Phalcon \Di \Injectable ;
23
23
use Guzzle \Http \Client as HttpClient ;
24
+ use Phosphorum \Exception \UrlException ;
24
25
25
26
/**
26
27
* Class OAuth
@@ -46,10 +47,12 @@ class OAuth extends Injectable
46
47
*/
47
48
public function __construct (Config $ config )
48
49
{
50
+ $ this ->logger = $ this ->getDI ()->get ('logger ' , ['auth ' ]);
51
+ $ this ->checkRedirectGitPath ($ config ->get ('redirectUri ' ));
52
+
49
53
$ this ->redirectUriAuthorize = $ config ->get ('redirectUri ' );
50
54
$ this ->clientId = $ config ->get ('clientId ' );
51
55
$ this ->clientSecret = $ config ->get ('clientSecret ' );
52
- $ this ->logger = $ this ->getDI ()->get ('logger ' , ['auth ' ]);
53
56
}
54
57
55
58
public function authorize ()
@@ -132,4 +135,30 @@ public function send($url, $parameters, $method = 'post')
132
135
return false ;
133
136
}
134
137
}
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
+ }
135
164
}
0 commit comments