private static async Task RunAsync()
        {
            SampleConfiguration config = SampleConfiguration.ReadFromJsonFile("appsettings.json");
            var appConfig = config.PublicClientApplicationOptions;
            var app       = PublicClientApplicationBuilder.CreateWithApplicationOptions(appConfig)
                            .Build();
            var httpClient = new HttpClient();

            MyInformation myInformation = new MyInformation(app, httpClient, config.MicrosoftGraphBaseEndpoint);
            await myInformation.DisplayMeAndMyManagerAsync();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the configuration from a json file
        /// </summary>
        /// <param name="path">Path to the configuration json file</param>
        /// <returns>SampleConfiguration as read from the json file</returns>
        public static SampleConfiguration ReadFromJsonFile(string path)
        {
            // .NET configuration
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location))
                          .AddJsonFile(path);

            var configuration = builder.Build();
            // Read the auth and graph endpoint config
            var config = new SampleConfiguration
            {
                PublicClientApplicationOptions = new PublicClientApplicationOptions()
            };

            configuration.Bind("Authentication", config.PublicClientApplicationOptions);
            config.MicrosoftGraphBaseEndpoint = configuration.GetValue <string>("WebAPI:MicrosoftGraphBaseEndpoint");
            return(config);
        }