Esempio n. 1
0
        public static async Task <bool> SubmitAsync(GraphUserInformation user)
        {
            HttpClient client = new HttpClient();

            try
            {
                string url = $"https://traininglabservices.azurewebsites.net/api/submissions/?id={user.id}&displayName={user.displayName}&emailAddress={user.userPrincipalName}&installId={Microsoft.Azure.Mobile.MobileCenter.InstallId}";


                var result = await client.PostAsync(url, null);
            }
            catch (Exception ex)
            {
            }

            return(true);
        }
Esempio n. 2
0
        public static async Task <GraphUserInformation> ValidateAsync()
        {
            GraphUserInformation authenticatedUser = null;

            string[] scopes = { "User.Read", "User.ReadBasic.All" };

            try
            {
                var result = await App.AuthenticationClient.AcquireTokenAsync(scopes);

                authenticatedUser = await GetUserProfileAsync(result.Token);
            }
            catch (Exception ex)
            {
            }



            return(authenticatedUser);
        }
Esempio n. 3
0
        private static async Task <GraphUserInformation> GetUserProfileAsync(string token)
        {
            GraphUserInformation user = new GraphUserInformation();

            HttpClient         client  = new HttpClient();
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me");

            message.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", token);

            HttpResponseMessage response = await client.SendAsync(message);

            string result = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                user = Newtonsoft.Json.JsonConvert.DeserializeObject <GraphUserInformation>(result);
            }
            else
            {
            }

            return(user);
        }