Skip to content

Commit

Permalink
Change error handling to remove special HTML body handling (since thi…
Browse files Browse the repository at this point in the history
…s has been fixed in the Java code) and add check for response code >= 400. Add error supression '@' for response array accessors.
  • Loading branch information
terrencegf committed May 25, 2017
1 parent 884858d commit 62a4e93
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
27 changes: 16 additions & 11 deletions src/Provider/CILogon.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,24 @@ protected function getScopeSeparator()
*/
protected function checkResponse(ResponseInterface $response, $data)
{
if ((gettype($data) == 'string') &&
(preg_match('/error="([^"]*)"/', $data, $matches))) {
$message = $matches[1];
if (preg_match('/error_description="([^"]*)"/', $data, $matches)) {
$message .= ': ' . urldecode($matches[1]);
}
throw new IdentityProviderException($message, 0, $data);
} elseif (!empty($data['error'])) {
$message = $data['error'];
$error = false;
$errcode = 0;
$errmsg = '';

if (!empty($data['error'])) {
$error = true;
$errmsg = $data['error'];
if (!empty($data['error_description'])) {
$message .= ': ' . $data['error_description'];
$errmsg .= ': ' . $data['error_description'];
}
throw new IdentityProviderException($message, 0, $data);
} elseif ($response->getStatusCode() >= 400) {
$error = true;
$errcode = $resopnse->getStatusCode();
$errmsg = $response->getReasonPhrase();
}

if ($error) {
throw new IdentityProviderException($errmsg, $errcode, $data);
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/Provider/CILogonResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(array $response = array())
*/
public function getId()
{
return $this->response['sub'] ?: null;
return @$this->response['sub'] ?: null;
}

/**
Expand All @@ -52,7 +52,7 @@ public function getId()
*/
public function getName()
{
return $this->response['name'] ?: null;
return @$this->response['name'] ?: null;
}

/**
Expand All @@ -62,7 +62,7 @@ public function getName()
*/
public function getGivenName()
{
return $this->response['given_name'] ?: null;
return @$this->response['given_name'] ?: null;
}

/**
Expand All @@ -83,7 +83,7 @@ public function getFirstName()
*/
public function getFamilyName()
{
return $this->response['family_name'] ?: null;
return @$this->response['family_name'] ?: null;
}

/**
Expand All @@ -104,7 +104,7 @@ public function getLastName()
*/
public function getEPPN()
{
return $this->response['eppn'] ?: null;
return @$this->response['eppn'] ?: null;
}

/**
Expand All @@ -114,7 +114,7 @@ public function getEPPN()
*/
public function getEPTID()
{
return $this->response['eptid'] ?: null;
return @$this->response['eptid'] ?: null;
}

/**
Expand All @@ -124,7 +124,7 @@ public function getEPTID()
*/
public function getEmail()
{
return $this->response['email'] ?: null;
return @$this->response['email'] ?: null;
}

/**
Expand All @@ -135,7 +135,7 @@ public function getEmail()
*/
public function getIdP()
{
return $this->response['idp'] ?: null;
return @$this->response['idp'] ?: null;
}

/**
Expand All @@ -146,7 +146,7 @@ public function getIdP()
*/
public function getIdPName()
{
return $this->response['idp_name'] ?: null;
return @$this->response['idp_name'] ?: null;
}

/**
Expand All @@ -156,7 +156,7 @@ public function getIdPName()
*/
public function getOU()
{
return $this->response['ou'] ?: null;
return @$this->response['ou'] ?: null;
}

/**
Expand All @@ -166,7 +166,7 @@ public function getOU()
*/
public function getAffiliation()
{
return $this->response['affiliation'] ?: null;
return @$this->response['affiliation'] ?: null;
}

/**
Expand Down

0 comments on commit 62a4e93

Please sign in to comment.