/// <summary>
        /// Creates the Customer Insights API by acquiring an access token from the app and constructing the client with proper HTTP headers.
        /// </summary>
        /// <param name="apiRegistrationConfig">The app registration config.</param>
        /// <param name="app">The app configured with client secrets and authority.</param>
        /// <returns>An instantiated and authorized Customer Insights API</returns>
        private static async Task <CustomerInsights> CreateCustomerInsightsApi(ApiRegistrationConfig apiRegistrationConfig, IConfidentialClientApplication app)
        {
            var accessToken = await AcquireAccessTokenAsync(app);

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, $"Bearer {accessToken}");
            httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiRegistrationConfig.ApiSubscriptionKey);

            var customerInsightsApi = new CustomerInsights(httpClient, false);

            return(customerInsightsApi);
        }
        /// <summary>
        /// Entry point for the program - creates and loads configs, builds app from app registration for auth, creates Customer Insights API client, and starts interactions.
        /// </summary>
        /// <returns>A task for the async main function.</returns>
        public static async Task Main()
        {
            AppRegistrationConfig appRegistrationConfig = new AppRegistrationConfig();
            ApiRegistrationConfig apiRegistrationConfig = new ApiRegistrationConfig();

            LoadConfigs(appRegistrationConfig, apiRegistrationConfig);

            IConfidentialClientApplication app = BuildClientApplication(appRegistrationConfig);

            CustomerInsights customerInsightsApi = await CreateCustomerInsightsApi(apiRegistrationConfig, app);

            var sampleInteractions = new SampleApiInteractions(customerInsightsApi);
            await sampleInteractions.StartAsync();
        }
        internal static async Task <CustomerInsights> ConnectAsync()
        {
            AppRegistrationConfig appRegistrationConfig = new AppRegistrationConfig();
            ApiRegistrationConfig apiRegistrationConfig = new ApiRegistrationConfig();

            LoadConfigs(appRegistrationConfig, apiRegistrationConfig);

            IConfidentialClientApplication app = BuildClientApplication(appRegistrationConfig);

            CustomerInsights customerInsightsApi = await CreateCustomerInsightsApi(apiRegistrationConfig, app);

            api = customerInsightsApi;


            return(customerInsightsApi);

            //var sampleInteractions = new SampleApiInteractions(customerInsightsApi);
            //await sampleInteractions.StartAsync();
        }
 public SampleApiInteractions(CustomerInsights api)
 {
     this.api = api;
 }