Exemple #1
0
        public async Task <IEnumerable <ConditionalAccessPolicyModel> > GetConditionalAccessPolicies(GraphServiceClient graphClient = null, HttpClient httpClient = null)
        {
            if (graphClient == null)
            {
                graphClient = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");
            }
            if (httpClient == null)
            {
                httpClient = HttpClientService.GetInstance("*****@*****.**", "5kep7353bC");
            }
            var conditionalAccessPolicies = new List <ConditionalAccessPolicyModel>();

            await GetConditionalAccessPolicyIds(httpClient, null);

            if (policyIds.Any())
            {
                var locations = await graphClient.Identity.ConditionalAccess.NamedLocations.Request().GetAsync();

                foreach (var policyId in policyIds.Distinct())
                {
                    var response = httpClient.GetAsync($"https://main.iam.ad.ext.azure.com/api/Policies/{policyId}").GetAwaiter().GetResult();
                    if (response.IsSuccessStatusCode)
                    {
                        var policy = JsonConvert.DeserializeObject <ConditionalAccessPolicyModel>(response.Content.ReadAsStringAsync().Result);
                        if (policy.conditions.namedNetworks.applyCondition)
                        {
                            if (policy.conditions.namedNetworks.includedNetworkIds.Any())
                            {
                                var locationNames = locations.Where(l => policy.conditions.namedNetworks.includedNetworkIds.Contains(l.Id)).Select(l => l.DisplayName).ToList();
                                policy.conditions.namedNetworks.includedNetworkIds.Clear();
                                policy.conditions.namedNetworks.includedNetworkIds.AddRange(locationNames);
                            }
                            if (policy.conditions.namedNetworks.excludedNetworkIds.Any())
                            {
                                var locationNames = locations.Where(l => policy.conditions.namedNetworks.excludedNetworkIds.Contains(l.Id)).Select(l => l.DisplayName).ToList();
                                policy.conditions.namedNetworks.excludedNetworkIds.Clear();
                                policy.conditions.namedNetworks.excludedNetworkIds.AddRange(locationNames);
                            }
                        }
                        conditionalAccessPolicies.Add(policy);
                    }
                    else
                    {
                    }
                }
            }

            return(conditionalAccessPolicies);
        }
Exemple #2
0
        public static async Task CreateDeviceCompliancePolicy(DeviceCompliancePolicy compliancePolicy)
        {
            var graphClient = GraphClient.GetInstance("a7223375-8d73-437d-a391-1c30f50afd49", "dc293766-b44d-48e6-bc3d-a14569148567", "JQXW_GIhdb3_74-h8U7e_ABFuR5u9vK937");

            try
            {
                if (compliancePolicy.ODataType == "#microsoft.graph.androidCompliancePolicy")
                {
                    var androidCompliancePolicy = (AndroidCompliancePolicy)compliancePolicy;
                    androidCompliancePolicy.ConditionStatementId = null;
                    compliancePolicy = androidCompliancePolicy;
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #3
0
        public async void CreateManagementConditions(IEnumerable <ManagementCondition> conditions)
        {
            var graphClient = GraphClient.GetInstance("a7223375-8d73-437d-a391-1c30f50afd49", "dc293766-b44d-48e6-bc3d-a14569148567", "JQXW_GIhdb3_74-h8U7e_ABFuR5u9vK937");

            foreach (var condition in conditions)
            {
                try
                {
                    await graphClient.DeviceManagement.ManagementConditions
                    .Request()
                    .AddAsync(condition);
                }
                catch (Exception ex)
                {
                }
            }
        }
Exemple #4
0
        public async void CreateManagementConditionStatements(IEnumerable <ManagementConditionStatement> conditionStatements)
        {
            var graphClient = GraphClient.GetInstance("a7223375-8d73-437d-a391-1c30f50afd49", "dc293766-b44d-48e6-bc3d-a14569148567", "JQXW_GIhdb3_74-h8U7e_ABFuR5u9vK937");

            foreach (var conditionStatement in conditionStatements)
            {
                await graphClient.DeviceManagement.ManagementConditionStatements
                .Request()
                .AddAsync(new ManagementConditionStatement()
                {
                    DisplayName         = conditionStatement.DisplayName,
                    Description         = conditionStatement.Description,
                    ApplicablePlatforms = conditionStatement.ApplicablePlatforms,
                    ETag = conditionStatement.ETag,
                    ManagementConditions = conditionStatement.ManagementConditions,
                });
            }
        }
Exemple #5
0
        public static async Task CreateGroupPolicyConfigurations(IEnumerable <GroupPolicyConfiguration> policies)
        {
            var graphClient = GraphClient.GetInstance("a7223375-8d73-437d-a391-1c30f50afd49", "dc293766-b44d-48e6-bc3d-a14569148567", "JQXW_GIhdb3_74-h8U7e_ABFuR5u9vK937");

            //Delete destination group policy configuration
            //var groupPolicyConfigurations = await graphClient.DeviceManagement.GroupPolicyConfigurations
            //       .Request()
            //       .GetAsync();
            //foreach (var groupPolicyConfiguration in groupPolicyConfigurations)
            //{
            //    await graphClient.DeviceManagement.GroupPolicyConfigurations[groupPolicyConfiguration.Id]
            //        .Request()
            //        .DeleteAsync();
            //}

            foreach (var policy in policies)
            {
                await CreateGroupPolicyConfiguraion(graphClient, policy);
            }
        }
Exemple #6
0
        public static async Task <AutomaticEnrollmentModel> GetAutomaticEnrollment()
        {
            var graphClient = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");
            var httpClient  = HttpClientService.GetInstance("*****@*****.**", "5kep7353bC");

            var servicePrincipals = await graphClient.ServicePrincipals.Request().Filter("appId eq '0000000a-0000-0000-c000-000000000000'").GetAsync();

            if (servicePrincipals.Any())
            {
                var intuneServiceId = servicePrincipals.First().Id;
                var response        = await httpClient.GetAsync($"https://main.iam.ad.ext.azure.com/api/MdmApplications/{intuneServiceId}");

                var content = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <AutomaticEnrollmentModel>(content));
                }
                else
                {
                }
            }
            return(null);
        }