Skip to content

Commit 699e62f

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

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-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: 40 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,42 @@ 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+
$this->logger->error(
145+
"Parameter GITHUB_REDIRECT_URI in .env file doesn't exist. Please, check setting in .env file and on Github."
146+
);
147+
return '';
148+
}
149+
150+
if (!stristr($url, '://')) {
151+
$this->logger->warning(
152+
'Authorization callback URL is wrong. Please, check setting in .env file and on Github.'
153+
);
154+
return '';
155+
}
156+
157+
if (stristr($url, '://', true) != $this->request->getScheme()) {
158+
$this->logger->warning(
159+
'HyperText Protocol in your application and in your setting file is different. Please, check setting in .env file and on Github.'
160+
);
161+
return '';
162+
}
163+
164+
if (substr($url, -1) != '/') {
165+
$this->logger->warning(
166+
'Authorization callback URL should contain slash in the end. Please, check setting in .env file and on Github.'
167+
);
168+
return '';
169+
}
170+
171+
return $url;
172+
}
135173
}

0 commit comments

Comments
 (0)