protected IEnumerable <XObject> GetXContent()
        {
            if (EntityId == null)
            {
                throw new ArgumentNullException("EntityId property");
            }
            yield return(new XAttribute(Saml2MetadataConstants.Message.EntityId, EntityId));

            yield return(new XAttribute(Saml2MetadataConstants.Message.Id, IdAsString));

            if (ValidUntil.HasValue)
            {
                yield return(new XAttribute(Saml2MetadataConstants.Message.ValidUntil, DateTimeOffset.UtcNow.AddDays(ValidUntil.Value).UtcDateTime.ToString("o", CultureInfo.InvariantCulture)));
            }
            yield return(new XAttribute(Saml2MetadataConstants.MetadataNamespaceNameX, Saml2MetadataConstants.MetadataNamespace));

            if (SPSsoDescriptor != null)
            {
                yield return(SPSsoDescriptor.ToXElement());
            }

            if (IdPSsoDescriptor != null)
            {
                yield return(IdPSsoDescriptor.ToXElement());
            }

            if (ContactPerson != null)
            {
                yield return(ContactPerson.ToXElement());
            }
        }
        public virtual EntityDescriptor ReadSPSsoDescriptor(string spMetadataXml)
        {
            var metadataXmlDocument = spMetadataXml.ToXmlDocument();

            var entityDescriptorElement = metadataXmlDocument.DocumentElement.SelectSingleNode($"//*[local-name()='{Saml2MetadataConstants.Message.EntityDescriptor}']") as XmlElement;

            if (entityDescriptorElement == null)
            {
                throw new Saml2RequestException("EntityDescriptorElement element not found in Metadata.");
            }

            if (entityDescriptorElement.NamespaceURI != Saml2MetadataConstants.MetadataNamespace.OriginalString)
            {
                throw new Saml2RequestException("Not Metadata.");
            }

            EntityId = entityDescriptorElement.Attributes[Saml2MetadataConstants.Message.EntityId].GetValueOrNull <string>();

            Id = entityDescriptorElement.Attributes[Saml2MetadataConstants.Message.Id].GetValueOrNull <Saml2Id>();

            var spSsoDescriptorElement = entityDescriptorElement[Saml2MetadataConstants.Message.SPSsoDescriptor, Saml2MetadataConstants.MetadataNamespace.OriginalString];

            if (spSsoDescriptorElement != null)
            {
                SPSsoDescriptor = new SPSsoDescriptor().Read(spSsoDescriptorElement);
            }

            return(this);
        }
        public virtual EntityDescriptor ReadSPSsoDescriptor(string spMetadataXml)
        {
            var metadataXmlDocument = spMetadataXml.ToXmlDocument();

            if (metadataXmlDocument.DocumentElement.NamespaceURI != Saml2MetadataConstants.MetadataNamespace.OriginalString)
            {
                throw new Saml2RequestException("Not Metadata.");
            }

            EntityId = metadataXmlDocument.DocumentElement.Attributes[Saml2MetadataConstants.Message.EntityId].GetValueOrNull <string>();

            Id = metadataXmlDocument.DocumentElement.Attributes[Saml2MetadataConstants.Message.Id].GetValueOrNull <Saml2Id>();

            var spSsoDescriptorElement = metadataXmlDocument.DocumentElement[Saml2MetadataConstants.Message.SPSsoDescriptor, Saml2MetadataConstants.MetadataNamespace.OriginalString];

            if (spSsoDescriptorElement != null)
            {
                SPSsoDescriptor = new SPSsoDescriptor().Read(spSsoDescriptorElement);
            }

            return(this);
        }