@@ -46,10 +46,10 @@ class OAuth extends Injectable
4646 */
4747 public function __construct (Config $ config )
4848 {
49- $ this ->redirectUriAuthorize = $ config ->get ('redirectUri ' );
49+ $ this ->logger = $ this ->getDI ()->get ('logger ' , ['auth ' ]);
50+ $ this ->redirectUriAuthorize = $ this ->checkRedirectGitPath ($ config ->get ('redirectUri ' ));
5051 $ this ->clientId = $ config ->get ('clientId ' );
5152 $ this ->clientSecret = $ config ->get ('clientSecret ' );
52- $ this ->logger = $ this ->getDI ()->get ('logger ' , ['auth ' ]);
5353 }
5454
5555 public function authorize ()
@@ -132,4 +132,45 @@ public function send($url, $parameters, $method = 'post')
132132 return false ;
133133 }
134134 }
135+
136+ /**
137+ * @param string $url
138+ *
139+ * @return string
140+ */
141+ protected function checkRedirectGitPath ($ url )
142+ {
143+ if (empty ($ url )) {
144+ $ errorMessage = 'Authorization callback URL in .env file doesn \'t exist. ' ;
145+ $ errorMessage .= 'Please, check setting in .env file and on Github. ' ;
146+
147+ $ this ->logger ->error ($ errorMessage );
148+ return '' ;
149+ }
150+
151+ if (!stristr ($ url , ':// ' )) {
152+ $ errorMessage = 'Authorization callback URL is wrong. Please, check setting in .env file and on Github. ' ;
153+
154+ $ this ->logger ->warning ($ errorMessage );
155+ return '' ;
156+ }
157+
158+ if (stristr ($ url , ':// ' , true ) != $ this ->request ->getScheme ()) {
159+ $ errorMessage = 'HyperText Protocol in your application and in your setting file are different. ' ;
160+ $ errorMessage .= 'Please, check setting in .env file and on Github. ' ;
161+
162+ $ this ->logger ->warning ($ errorMessage );
163+ return '' ;
164+ }
165+
166+ if (substr ($ url , -1 ) != '/ ' ) {
167+ $ errorMessage = 'Authorization callback URL should contain slash in the end. ' ;
168+ $ errorMessage .= 'Please, check setting in .env file and on Github. ' ;
169+
170+ $ this ->logger ->warning ($ errorMessage );
171+ return '' ;
172+ }
173+
174+ return $ url ;
175+ }
135176}
0 commit comments