I have developed an asp.net core 6 console application that is hosted inside an on-premises windows VM. and i am connecting to SharePoint uisng a clientID, ClientSecret & Certifficate, as follow:-

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PnP.Core.Auth;
using PnP.Core.Model.SharePoint;
using PnP.Core.Model.Teams;
using PnP.Core.QueryModel;
using PnP.Core.Services;
using PnP.Core.Services.Builder.Configuration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
using static System.Net.Mime.MediaTypeNames;

namespace ConsoleApp4
    internal class Program
        static async Task Main(string[] args)
            var tenantId = "b***c";
            var clientId = "7*****9";
            var certificatePath = @"c:\CERT\SPDashBoardIntegration.pfx";
            var certificatePassword = "***";

            // Initialize a new service collection
            var serviceCollection = new ServiceCollection();

            // Load the certificate
            var certificate = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.Exportable);

            // Configure logging
            serviceCollection.AddLogging(builder =>

            // Add and configure PnP Core SDK
            serviceCollection.AddPnPCore(options =>
                options.PnPContext.GraphFirst = true; // Set true if you prefer to use Graph over CSOM when possible
                                                      // options.HttpRequests.UserAgent = "ISV|Contoso|ProductX";
                options.Sites.Add("SiteToWorkWith", new PnPCoreSiteOptions
                    SiteUrl = "https://********.sharepoint.com/sites/********-******",
                    AuthenticationProvider = new X509CertificateAuthenticationProvider(clientId, tenantId, certificate)
        int i = 0;
        // Build the service provider
        var serviceProvider = serviceCollection.BuildServiceProvider();

        // Use the service provider to get the IPnPContextFactory instance
        var pnpContextFactory = serviceProvider.GetRequiredService<IPnPContextFactory>();

        // Now you can use the IPnPContextFactory to get a PnPContext and perform operations
        var context = await pnpContextFactory.CreateAsync("SiteToWorkWith");
        // Assume the fields where not yet loaded, so loading them with the list
        var workOrderList = context.Web.Lists.GetByTitle("Work Orders", p => p.Title,
                                                             p => p.Fields.QueryProperties(p => p.InternalName,
                                                                                           p => p.FieldTypeKind,
                                                                                           p => p.TypeAsString,
                                                                                           p => p.Title));

now the VM itself is secure that only authorized users can access it. but my main concern is how the data mainly (ClientSecret, ClientID & Certificate) that will get sent from my console application to SharePoint online api will be secured over the network? or it is already secure? if not then how i can secure it? i mean will the (ClientSecret, ClientID & Certificate) be exposed over the network till it reaches the SharePoint online Api ??



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.