Skip to content

Commit 4b7047c

Browse files
John-Holt-TessellaJohn Holt
andauthored
On Build: Satisfy Psalm Config (#689)
* Move globals in OIDC and tidy, remove static ref in Download, conform to php7 in processing * implement strpos properly --------- Co-authored-by: John Holt <John.Holt@diamond.ac.uk>
1 parent ab0c56e commit 4b7047c

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

api/src/Authentication/Type/OIDC.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
class OIDC extends AuthenticationParent implements AuthenticationInterface
1010
{
11-
private $providerConfig = array();
11+
//** Cache for providerConfig */
12+
private $providerConfigCache = null;
1213

13-
private function getEndpoints() {
14-
if (empty($this->providerConfig)) {
15-
global $sso_url, $oidc_client_id, $oidc_client_secret;
14+
private function getProviderConfig() {
15+
global $sso_url, $oidc_client_id, $oidc_client_secret;
16+
if (is_null($this->providerConfigCache)) {
1617

1718
$ch = curl_init();
1819
curl_setopt($ch, CURLOPT_URL, 'https://' . $sso_url . '/.well-known/openid-configuration');
@@ -27,21 +28,21 @@ private function getEndpoints() {
2728
|| !isset($newProviderConfig->authorization_endpoint)
2829
|| !isset($newProviderConfig->token_endpoint)) {
2930
error_log("OIDC Authentication provider replied with invalid JSON body");
30-
return;
31+
return null;
3132
}
3233
$newProviderConfig->b64ClientCreds = base64_encode(
3334
$oidc_client_id . ":" . $oidc_client_secret
3435
);
3536

36-
$this->providerConfig = $newProviderConfig;
37+
$this->providerConfigCache = $newProviderConfig;
3738
}
39+
return $this->providerConfigCache;
3840
}
3941

4042
private function getUser($token)
4143
{
42-
$this->getEndpoints();
4344
$ch = curl_init();
44-
curl_setopt($ch, CURLOPT_URL, $this->providerConfig->userinfo_endpoint);
45+
curl_setopt($ch, CURLOPT_URL, $this->getProviderConfig()->userinfo_endpoint);
4546
curl_setopt($ch, CURLOPT_HEADER, 0);
4647
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
4748
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -74,32 +75,30 @@ function check()
7475

7576
function authorise()
7677
{
77-
$this->getEndpoints();
7878
global $oidc_client_id;
7979
$redirect_url = Utils::filterParamFromUrl($_SERVER["HTTP_REFERER"], "code");
8080

81-
return ( $this->providerConfig->authorization_endpoint .
81+
return ( $this->getProviderConfig()->authorization_endpoint .
8282
'?response_type=code&client_id=' . $oidc_client_id .
8383
'&redirect_uri=' . $redirect_url
8484
);
8585
}
8686

8787
function authenticateByCode($code)
8888
{
89-
$this->getEndpoints();
9089
global $cacert, $oidc_client_secret, $oidc_client_id, $cookie_key;
9190

9291
$redirect_url = Utils::filterParamFromUrl($_SERVER["HTTP_REFERER"], "code");
9392

9493
$ch = curl_init();
95-
curl_setopt($ch, CURLOPT_URL, $this->providerConfig->token_endpoint .
94+
curl_setopt($ch, CURLOPT_URL, $this->getProviderConfig()->token_endpoint .
9695
'?grant_type=authorization_code&redirect_uri=' .
9796
$redirect_url .
9897
"&code=" . $code
9998
);
10099
curl_setopt($ch, CURLOPT_HEADER, 0);
101100
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
102-
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->providerConfig->b64ClientCreds));
101+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->getProviderConfig()->b64ClientCreds));
103102
$response = curl_exec($ch);
104103
curl_close($ch);
105104

api/src/Page/Download.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,13 @@ function set_mime_content($response, $filename, $prefix = null)
527527

528528
function _set_disposition_attachment($response, $filename) {
529529
$response->headers->set("Content-Disposition",
530-
ResponseHeaderBag::makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename)
530+
(new ResponseHeaderBag())->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename)
531531
);
532532
}
533533

534534
function _set_disposition_inline($response) {
535535
$response->headers->set("Content-Disposition",
536-
ResponseHeaderBag::makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, '')
536+
(new ResponseHeaderBag())->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, '')
537537
);
538538
}
539539

api/src/Page/Processing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function _get_downstreams($dcid = null, $aid = null) {
424424
if ($downstream["PARAMETERS"]) {
425425
$str_params = explode(',', $downstream["PARAMETERS"]);
426426
foreach ($str_params as $str_param) {
427-
if (str_contains($str_param, '=')) {
427+
if (strpos($str_param, '=') !== false) {
428428
list($key, $value) = explode('=', $str_param);
429429
$params[$key] = $value;
430430
}

0 commit comments

Comments
 (0)