SimpleSAMLPHP as SP configuration
===

According to SimpleSAML quickstart for SP's I can use the following to 
require auth against "emerson-sp" authsource in my index (entry point) file:

    $as = new SimpleSAML_Auth_Simple('emerson-sp');
    $as->requireAuth();

When I do this it searches for emerson-sp authsource in config, for IdP 
metadata, redirects to IdP service, I successfully login there and when it 
redirects me back to assertion url, there is the following code:

    global $session;
    $session->doLogin('saml2', $authData);

this is in finishLogin function of /simplesamlphp/www/saml2/sp/AssertionConsumerService.php file. This method of SimpleSAML_Session class does the following:

    public function doLogin($authority, array $data = NULL) {
           ...........
           $this->authData[$authority] = $data;
           $this->authority = $authority;

Note that $authority param passed to this function is hardcoded to "saml2" 
in AssertionConsumerService.php. So SimpleSAML_Session singleton has the 
first (and the only) index of its authData property = 'saml2'. And seems 
like I can't change it as it is hardcoded in core file of simpleSamlPHP.

**Question #1:** am I missing something and this "saml2" hardcoded value is correct in SimpleSAMLPHP core in /simplesamlphp/www/saml2/sp/AssertionConsumerService.php file?  

Now if we get back to the 

    $as = new SimpleSAML_Auth_Simple('emerson-sp');
    $as->requireAuth();

and open SimpleSAML_Auth_Simple class code we'll see the following:

    public function __construct($authSource) {
            assert('is_string($authSource)');

            $this->authSource = $authSource;
    }

so the parameter passed to constructor is saved as ::authSource property. And 
when I use $as = new SimpleSAML_Auth_Simple('emerson-sp'); in my entry point 
file I have authSource = 'emerson-sp'. If we open SimpleSAML_Auth_Simple::requireAuth() method, which I also call from index entry point file (see above), we'll see:

    $session = SimpleSAML_Session::getInstance();
    if ($session->isValid($this->authSource)) {
    ....

so in my case it is called like $session->isValid('emerson-sp'). Now isValid 
method of SimpleSAML_Session has the code:

        public function isValid($authority) {
                ......
                if (!isset($this->authData[$authority])) {
                        SimpleSAML_Logger::debug('Session: '. var_export($authority, TRUE) .' not valid because we are not authenticated.');
                        return FALSE;
                }

But as I mentioned above $this->authData has the only "saml2" element that 
was called so from hardcoded value from Assertion script, while $authority 
param passed here is "emerson-sp". So it fails on this check and I can' figure out the following:

**Question #2:** It's like a naming conflict which I'm almost sure is because of 
misconfiguration on my end, but I don't know how to solve it properly, 
obviously without hacking core SimpleSAMLPHP code - briefly, "emerson-sp" authsource which I use in my config and requireAuth() call does not match hardcoded "saml2" value in SimpleSAMLPHP code. If I change "emerson-sp" to "saml2" in config/authsources and metadata, then my IdP can't find this entityID in their config.

Thanks in advance!
