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,31 @@ 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
+ $ 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
+ }
135
165
}
0 commit comments