function getIDPForRole()

in tampermonkey.js [103:124]


  function getIDPForRole($saml, role) {
    const $attribute = $saml.find('[Name=\'https://aws.amazon.com/SAML/Attributes/Role\']')
      .filter((idx, element) => {
        return element.localName === 'Attribute' && element.namespaceURI === 'urn:oasis:names:tc:SAML:2.0:assertion';
      });
    const $value = $attribute.find(':contains(\''+role+'\')')
      .filter((idx, element) => {
        return element.localName === 'AttributeValue' && element.namespaceURI === 'urn:oasis:names:tc:SAML:2.0:assertion';
      });

    if(!$value || !$value.length) {
      throw new Error('Failed to find IDP ARN for selected role: '+role);
    }

    // IDP is usually the first part, but not always
    var parts = $value.text().split(',');
    if(parts[0].indexOf(':saml-provider/') !== -1) {
      return parts[0];
    } else {
      return parts[1];
    }
  }