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 ReadIdPSsoDescriptor(string idPMetadataXml)
        {
            var metadataXmlDocument = idPMetadataXml.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 idPSsoDescriptorElement = entityDescriptorElement[Saml2MetadataConstants.Message.IdPSsoDescriptor, Saml2MetadataConstants.MetadataNamespace.OriginalString];

            if (idPSsoDescriptorElement != null)
            {
                IdPSsoDescriptor = new IdPSsoDescriptor().Read(idPSsoDescriptorElement);
            }

            return(this);
        }
        public virtual EntityDescriptor ReadIdPSsoDescriptor(string idPMetadataXml)
        {
            var metadataXmlDocument = idPMetadataXml.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 idPSsoDescriptorElement = metadataXmlDocument.DocumentElement[Saml2MetadataConstants.Message.IdPSsoDescriptor, Saml2MetadataConstants.MetadataNamespace.OriginalString];

            if (idPSsoDescriptorElement != null)
            {
                IdPSsoDescriptor = new IdPSsoDescriptor().Read(idPSsoDescriptorElement);
            }

            return(this);
        }