public IList <SAMLCredential> GetRolesFromAssertion() { var payload = System.Text.Encoding.Default.GetString(Convert.FromBase64String(this.Assertion)); IList <SAMLCredential> lstSAML = new List <SAMLCredential>(); XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(payload); XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xDoc.NameTable); xmlNamespaceManager.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion"); foreach (XmlElement attribute in xDoc.SelectNodes(".//saml:Attribute[@Name]", xmlNamespaceManager)) { if (attribute.GetAttribute("Name") == "https://aws.amazon.com/SAML/Attributes/Role") { foreach (XmlElement value in attribute.SelectNodes("saml:AttributeValue", xmlNamespaceManager)) { string[] array = value.InnerText.Split(','); AmazonResourceName arnRole = AmazonResourceName.Parse(array[0]); AmazonResourceName arnPrincipal = AmazonResourceName.Parse(array[1]); lstSAML.Add(new SAMLCredential { RoleArn = arnRole, PrincipalArn = arnPrincipal }); } } } return(lstSAML); }
/// <summary> /// Parse Credential from Value of KeyValuePair /// </summary> /// <param name="r">KeyValuePair with value set as full ARN of Credential</param> public SAMLCredential(KeyValuePair <string, string> r) { string[] array = r.Value.Split(','); RoleArn = AmazonResourceName.Parse(array[0]); PrincipalArn = AmazonResourceName.Parse(array[1]); }