示例#1
0
 public async static Task UpdateIosManagedAppProtection(string protectionId, IosManagedAppProtection protection)
 {
     var graphClient    = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");
     var iosProtections = await graphClient.DeviceAppManagement.IosManagedAppProtections[protectionId]
                          .Request()
                          .UpdateAsync(protection);
 }
示例#2
0
        public static async Task <IEnumerable <GroupPolicyConfiguration> > GetGroupPolicyConfigurations()
        {
            var graphClient = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");

            var groupPolicyConfigurations = await graphClient.DeviceManagement.GroupPolicyConfigurations
                                            .Request()
                                            .Expand(p => p.Assignments)
                                            .GetAsync();

            foreach (var policy in groupPolicyConfigurations)
            {
                var definitionValues = await graphClient.DeviceManagement.GroupPolicyConfigurations[policy.Id].DefinitionValues
                                       .Request()
                                       .Expand(d => d.Definition)
                                       .GetAsync();
                policy.DefinitionValues = definitionValues;

                foreach (var definitionValue in definitionValues)
                {
                    var presentationValues = await graphClient.DeviceManagement.GroupPolicyConfigurations[policy.Id].DefinitionValues[definitionValue.Id]
                                             .PresentationValues
                                             .Request()
                                             .GetAsync();
                    definitionValue.PresentationValues = presentationValues;

                    var presentations = await graphClient.DeviceManagement.GroupPolicyDefinitions[definitionValue.Definition.Id]
                                        .Presentations
                                        .Request()
                                        .GetAsync();
                    definitionValue.Definition.Presentations = presentations;
                }
            }
            return(groupPolicyConfigurations);
        }
示例#3
0
        public static async Task UpdateAutomaticEnrollment(AutomaticEnrollmentModel enrollment)
        {
            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 requestUrl      = $"https://main.iam.ad.ext.azure.com/api/MdmApplications/{intuneServiceId}?mdmAppliesToChanged=true&mamAppliesToChanged=true";
                //https://main.iam.ad.ext.azure.com/api/MdmApplications/26438a56-a35d-4f21-9178-4865b27c1d75?mdmAppliesToChanged=true&mamAppliesToChanged=false
                var settings = new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Include
                };
                var content     = JsonConvert.SerializeObject(enrollment, settings);
                var httpContent = new StringContent(content, Encoding.UTF8, "application/json");
                var response    = await httpClient.PutAsync(requestUrl, httpContent);

                if (!response.IsSuccessStatusCode)
                {
                }
            }
        }
示例#4
0
        public async Task CreateConditionalAccessPolicies(IEnumerable <ConditionalAccessPolicyModel> policies)
        {
            var graphClient = GraphClient.GetInstance("a7223375-8d73-437d-a391-1c30f50afd49", "dc293766-b44d-48e6-bc3d-a14569148567", "JQXW_GIhdb3_74-h8U7e_ABFuR5u9vK937");
            var httpClient  = HttpClientService.GetInstance("*****@*****.**", "OsiN20mhqA");

            //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 locations = await graphClient.Identity.ConditionalAccess.NamedLocations.Request().GetAsync();

            var targetPolicies = await GetConditionalAccessPolicies(graphClient, httpClient);

            foreach (var policy in policies)
            {
                try
                {
                    var targetPolicy = targetPolicies.FirstOrDefault(p => p.policyName.Equals(policy.policyName));
                    if (targetPolicy != null)
                    {
                        await UpdateConditionalAccessPolicy(httpClient, targetPolicy.policyId, policy, locations);
                    }
                    else
                    {
                        await CreateConditionalAccessPolicy(graphClient, httpClient, policy, locations);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
示例#5
0
        public static async Task <IEnumerable <DeviceCompliancePolicy> > GetDeviceCompliancePolicies()
        {
            var graphClient = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");

            var policies = await graphClient.DeviceManagement.DeviceCompliancePolicies.Request().Expand(p => p.Assignments).GetAsync();

            return(policies);
        }
示例#6
0
        public async Task UpdateConditionalAccessPolicy(string policyId, ConditionalAccessPolicyModel policy)
        {
            var graphClient = GraphClient.GetInstance("a7223375-8d73-437d-a391-1c30f50afd49", "dc293766-b44d-48e6-bc3d-a14569148567", "JQXW_GIhdb3_74-h8U7e_ABFuR5u9vK937");
            var httpClient  = HttpClientService.GetInstance("*****@*****.**", "OsiN20mhqA");
            var locations   = await graphClient.Identity.ConditionalAccess.NamedLocations.Request().GetAsync();

            await UpdateConditionalAccessPolicy(httpClient, policyId, policy, locations);
        }
示例#7
0
        public async static Task <IEnumerable <IosManagedAppProtection> > GetIosManagedAppProtections()
        {
            var graphClient    = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");
            var iosProtections = await graphClient.DeviceAppManagement.IosManagedAppProtections
                                 .Request()
                                 .GetAsync();

            return(iosProtections);
        }
示例#8
0
        public async Task <IEnumerable <ManagementConditionStatement> > GetManagementConditionStatements()
        {
            var graphClient = GraphClient.GetInstance("d6e01331-be4e-4114-86f1-09f2a9252679", "46514c3a-1b90-426d-949f-92e8be67da29", "sxw~0_yLYS6l1w~_ny5qf1Nr7-p2D4XGEE");

            var conditionStatements = await graphClient.DeviceManagement.ManagementConditionStatements
                                      .Request()
                                      .GetAsync();

            return(conditionStatements);
        }
示例#9
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);
        }
示例#10
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)
            {
            }
        }
示例#11
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)
                {
                }
            }
        }
示例#12
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,
                });
            }
        }
示例#13
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);
            }
        }
示例#14
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);
        }