Skip to content

Commit 16ad361

Browse files
added method in OAuth for add proper redirect url
1 parent 234fd6b commit 16ad361

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ switch to the relevant [branch][:branch:]/[tag][:tags:].
2020

2121
The current version can be seen at [Phosphorum Wiki][:wiki:].
2222

23+
## Github authorization
24+
Forum has possibility to authorize users with Github. Please set `GITHUB_CLIENT_ID`, `GITHUB_SECRET`, `GITHUB_REDIRECT_URI` parameters in your `.env` file.
25+
2326
## License
2427

2528
Phosphorum is an open-sourced software licensed under the [New BSD License][:license:].<br>

app/library/Github/OAuth.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)