コード例 #1
0
    public static async Task <bool> ImportCaConfig(string policy, string clientId = null)
    {
        SignalRMessage signalR = new SignalRMessage();

        signalR.clientId = clientId;

        ModernWorkplaceConcierge.Helpers.ConditionalAccessPolicy conditionalAccessPolicy = JsonConvert.DeserializeObject <ModernWorkplaceConcierge.Helpers.ConditionalAccessPolicy>(policy);

        conditionalAccessPolicy.id               = null;
        conditionalAccessPolicy.state            = "disabled";
        conditionalAccessPolicy.createdDateTime  = null;
        conditionalAccessPolicy.modifiedDateTime = null;


        // Check for device state and display warning (API issue)

        if (conditionalAccessPolicy.conditions.deviceStates != null)
        {
            signalR.sendMessage("Warning device states are currently not imported by the Graph API, you need to enable them manually on the policy!");
        }

        if (conditionalAccessPolicy.sessionControls != null && conditionalAccessPolicy.sessionControls.applicationEnforcedRestrictions != null)
        {
            signalR.sendMessage("Warning you need to enable Exchange online and SharePoint online for app enforced restrictions!");
        }

        try
        {
            string requestContent = JsonConvert.SerializeObject(conditionalAccessPolicy, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting        = Formatting.Indented
            });

            var success = await GraphHelper.AddConditionalAccessPolicyAsync(requestContent, clientId);

            signalR.sendMessage("Success: imported CA policy: '" + success.displayName + "'");
            return(true);
        }
        catch
        {
            signalR.sendMessage("Discarding tenant specific information for CA policy: '" + conditionalAccessPolicy.displayName + "'");
            // remove Id's
            conditionalAccessPolicy.conditions.users.includeUsers  = new string[] { "none" };
            conditionalAccessPolicy.conditions.users.excludeUsers  = null;
            conditionalAccessPolicy.conditions.users.includeGroups = null;
            conditionalAccessPolicy.conditions.users.excludeGroups = null;
            conditionalAccessPolicy.conditions.users.includeRoles  = null;
            conditionalAccessPolicy.conditions.users.excludeRoles  = null;

            conditionalAccessPolicy.conditions.applications.includeApplications = new string[] { "none" };
            conditionalAccessPolicy.conditions.applications.excludeApplications = null;

            string requestContent = JsonConvert.SerializeObject(conditionalAccessPolicy, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting        = Formatting.Indented
            });

            var success = await GraphHelper.AddConditionalAccessPolicyAsync(requestContent, clientId);

            signalR.sendMessage("Success: imported CA policy: '" + success.displayName + "'");
            return(true);
        }
    }