* nate <
nram...@gmail.com> [2018-06-08 00:30]:
> $as = new \SimpleSAML\Auth\Simple('default-sp');
> $as->requireAuth();
> $nameid = $as->getAuthData('saml:sp:NameID');
That's correct. You simply fail to take into account that a NameID is
a complex data structure (an XML element with XML attributes and
string content on-the-wire; SimpleSAMLphp exposes this as nested PHP
arrays), not a plain string. Therefore your comparison must always fail:
This should be obvious from the dumped value:
[...]
The constituent parts of the NameID are exposed via the API, e.g.:
print "NameIDFormat: " . $nameid->Format . "\n";
print "NameID NameQualifier: " . $nameid->NameQualifier. "\n";
print "NameID value: " . $nameid->value . "\n";
So the last one ($nameid->value) is what you'd need to compare
against.
BUT you must also take the Format into account, and depending on the
format also some of the qualifiers (NameQualifier as the asserting
party's entityID, and sometimes even SPNameQualifier as the relying
party's entityID, i.e., your own), e.g. the value of a 'persistent'
NameID is *only* unique if you qualify it with $nameid->NameQualifier
at least.
Also note that the example NameID you post is incorrect, as its format
is "transient" but it's value is not a transient value, but an email
address. So the IDP sending this is misconfigured.
Transient NameIDs serve no purpose other than possibly coordinating
logout with the IDP, noone should care about their values, as
transient NameIDs to not suitably identify a subject to an
application.
So correct code needs to check for the nameid->Format and would only
assume its value to be an email address if the NameFormat says so:
The standard NameID formats are part of SAML Core,
https://wiki.oasis-open.org/security e.g. the current "merged" version
http://www.oasis-open.org/committees/download.php/56776/sstc-saml-core-errata-2.0-wd-07.pdf
Section 8.3 has the "Name Identifier Format Identifiers", so email
(8.3.2) is "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress".
So:
* the IDP needs to be fixed to set the correct format
* your code needs to be expanded to check the format
* your code needs to be expaneded to only compare the value of a
NameID of the correct/expected format.
If your SP also federates with other IDPs you'll have to have code for
all kinds of NameID formats, of course.
-peter