Skip to content

Commit

Permalink
On Build: Satisfy Psalm Config (#689)
Browse files Browse the repository at this point in the history
* Move globals in OIDC and tidy, remove static ref in Download, conform to php7 in processing

* implement strpos properly

---------

Co-authored-by: John Holt <[email protected]>
  • Loading branch information
John-Holt-Tessella and John Holt authored Nov 2, 2023
1 parent ab0c56e commit 4b7047c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
25 changes: 12 additions & 13 deletions api/src/Authentication/Type/OIDC.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

class OIDC extends AuthenticationParent implements AuthenticationInterface
{
private $providerConfig = array();
//** Cache for providerConfig */
private $providerConfigCache = null;

private function getEndpoints() {
if (empty($this->providerConfig)) {
global $sso_url, $oidc_client_id, $oidc_client_secret;
private function getProviderConfig() {
global $sso_url, $oidc_client_id, $oidc_client_secret;
if (is_null($this->providerConfigCache)) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $sso_url . '/.well-known/openid-configuration');
Expand All @@ -27,21 +28,21 @@ private function getEndpoints() {
|| !isset($newProviderConfig->authorization_endpoint)
|| !isset($newProviderConfig->token_endpoint)) {
error_log("OIDC Authentication provider replied with invalid JSON body");
return;
return null;
}
$newProviderConfig->b64ClientCreds = base64_encode(
$oidc_client_id . ":" . $oidc_client_secret
);

$this->providerConfig = $newProviderConfig;
$this->providerConfigCache = $newProviderConfig;
}
return $this->providerConfigCache;
}

private function getUser($token)
{
$this->getEndpoints();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->providerConfig->userinfo_endpoint);
curl_setopt($ch, CURLOPT_URL, $this->getProviderConfig()->userinfo_endpoint);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Expand Down Expand Up @@ -74,32 +75,30 @@ function check()

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

return ( $this->providerConfig->authorization_endpoint .
return ( $this->getProviderConfig()->authorization_endpoint .
'?response_type=code&client_id=' . $oidc_client_id .
'&redirect_uri=' . $redirect_url
);
}

function authenticateByCode($code)
{
$this->getEndpoints();
global $cacert, $oidc_client_secret, $oidc_client_id, $cookie_key;

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

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->providerConfig->token_endpoint .
curl_setopt($ch, CURLOPT_URL, $this->getProviderConfig()->token_endpoint .
'?grant_type=authorization_code&redirect_uri=' .
$redirect_url .
"&code=" . $code
);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->providerConfig->b64ClientCreds));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $this->getProviderConfig()->b64ClientCreds));
$response = curl_exec($ch);
curl_close($ch);

Expand Down
4 changes: 2 additions & 2 deletions api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,13 @@ function set_mime_content($response, $filename, $prefix = null)

function _set_disposition_attachment($response, $filename) {
$response->headers->set("Content-Disposition",
ResponseHeaderBag::makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename)
(new ResponseHeaderBag())->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename)
);
}

function _set_disposition_inline($response) {
$response->headers->set("Content-Disposition",
ResponseHeaderBag::makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, '')
(new ResponseHeaderBag())->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, '')
);
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/Page/Processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function _get_downstreams($dcid = null, $aid = null) {
if ($downstream["PARAMETERS"]) {
$str_params = explode(',', $downstream["PARAMETERS"]);
foreach ($str_params as $str_param) {
if (str_contains($str_param, '=')) {
if (strpos($str_param, '=') !== false) {
list($key, $value) = explode('=', $str_param);
$params[$key] = $value;
}
Expand Down

0 comments on commit 4b7047c

Please sign in to comment.