Ejemplo n.º 1
0
        public async Task RunAsync()
        {
            AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");

            app = new PublicClientApplication(config.ClientId, config.Authority);
            // string[] scopes = { "User.ReadWrite" };

            var myInfo = new MyInformation();

            AuthenticationResult authenticationResult = await myInfo.AcquireATokenFromCacheOrDeviceCodeFlow(Scopes);

            if (authenticationResult != null)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"{authenticationResult.Account.Username} successfully signed-in");
                var accessToken = authenticationResult.AccessToken;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://graph.microsoft.com/v1.0/");
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                    //Use open extensions
                    await AddRoamingProfileInformationAsync(client);
                    await RetrieveRoamingProfileInformationAsync(client);
                    await UpdateRoamingProfileInformationAsync(client);
                    await DeleteRoamingProfileInformationAsync(client);
                }
            }
        }
Ejemplo n.º 2
0
        static async Task RunAsync(string[] args)
        {
            AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
            var app = new PublicClientApplication(config.ClientId, config.Authority);

            MyInformation myInformation = new MyInformation(app);
            await myInformation.DisplayMeAndMyManagerAsync();

            var openExtensionsDemo = new OpenExtensionsDemo(app);
            await openExtensionsDemo.RunAsync();

            var schemaExtensionDemo = new SchemaExtensionsDemo(app);
            await schemaExtensionDemo.RunAsync();

            System.Console.WriteLine("Press ENTER to continue.");
            System.Console.ReadLine();
        }
        static void Main(string[] args)
        {
            MyInformation myInformation = new MyInformation();

            try
            {
                myInformation.DisplayMeAndMyManagerAsync().Wait();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
            }

            RunAsync(args).GetAwaiter().GetResult();
        }