Ejemplo n.º 1
0
        public bool ValidateTenantAgainstDomain(string domain, string tenantId)
        {
            //https://login.microsoftonline.com/feloniousmultitasking.com/federationmetadata/2007-06/federationmetadata.xml
            var fedmx = $"https://login.microsoftonline.com/{domain}/federationmetadata/2007-06/federationmetadata.xml";
            var c     = new WebClient();

            try
            {
                var x         = XDocument.Load(fedmx);
                var val       = x.Element(XName.Get("EntityDescriptor", "urn:oasis:names:tc:SAML:2.0:metadata")).Attribute(XName.Get("entityID"));
                var fedTenant = Util.GetTenantIdFromIdPName(val.Value);
                Tc.TrackEvent("UserTenantValidation", new Dictionary <string, string> {
                    { "Domain", domain }, { "TenantId", tenantId }, { "ResolvedTenantId", fedTenant }
                });
                return(fedTenant == tenantId);
            }
            catch (Exception ex)
            {
                Tc.TrackException(ex);
                return(false);
            }
        }