@@ -46,10 +46,10 @@ class OAuth extends Injectable
46
46
*/
47
47
public function __construct (Config $ config )
48
48
{
49
- $ this ->redirectUriAuthorize = $ config ->get ('redirectUri ' );
49
+ $ this ->logger = $ this ->getDI ()->get ('logger ' , ['auth ' ]);
50
+ $ this ->redirectUriAuthorize = $ this ->checkRedirectGitPath ($ config ->get ('redirectUri ' ));
50
51
$ this ->clientId = $ config ->get ('clientId ' );
51
52
$ this ->clientSecret = $ config ->get ('clientSecret ' );
52
- $ this ->logger = $ this ->getDI ()->get ('logger ' , ['auth ' ]);
53
53
}
54
54
55
55
public function authorize ()
@@ -132,4 +132,45 @@ public function send($url, $parameters, $method = 'post')
132
132
return false ;
133
133
}
134
134
}
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
+ }
135
176
}
0 commit comments