Skip to content

Commit a1e25f1

Browse files
committed
Allow NameIDType objects to be seen in a JSON output
A cherry pick of the prs on saml2-legacy
1 parent 7a68eab commit a1e25f1

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/SAML2/XML/saml/NameIDType.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
use SAML2\Constants;
1515
use SAML2\DOMDocumentFactory;
1616
use Serializable;
17+
use JsonSerializable;
1718

18-
abstract class NameIDType implements Serializable
19+
abstract class NameIDType implements Serializable, \JsonSerializable
1920
{
2021
use IDNameQualifiersTrait;
2122

@@ -267,4 +268,26 @@ public function __toString()
267268

268269
return $doc->saveXML($ele);
269270
}
271+
272+
273+
/**
274+
* Because we have mostly protected attributes we do not look
275+
* interesting when converted into JSON. This allows for good
276+
* visibility from JSON which is used on the admin/test login page
277+
* when showing the attributes for the user.
278+
*
279+
* @return array associative array of defined object accessible
280+
* non-static properties for the specified object in scope.
281+
*/
282+
public function jsonSerialize(): array
283+
{
284+
return [
285+
'NameQualifier' => $this->getNameQualifier(),
286+
'SPNameQualifier' => $this->getSPNameQualifier(),
287+
'nodeName' => $this->nodeName,
288+
'Format' => $this->Format,
289+
'SPProvidedID' => $this->SPProvidedID,
290+
'value' => $this->value
291+
];
292+
}
270293
}

0 commit comments

Comments
 (0)