Skip to content

Commit

Permalink
Remove unused function CallMicrosoftGraph (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabricio Catae committed Feb 22, 2017
1 parent 100f621 commit 84b1086
Showing 1 changed file with 19 additions and 47 deletions.
66 changes: 19 additions & 47 deletions src/Arda.Main/Utils/TokenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,24 @@ public static async Task<AuthenticationResult> GetAccessToken(HttpContext contex
return await authContext.AcquireTokenAsync(Startup.GraphResourceId, credential);
}

private static async Task<IActionResult> CallMicrosoftGraph(HttpContext context)
{
AuthenticationResult result = null;

try
{
string userObjectID = context.User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new SessionCache(userObjectID, context));
ClientCredential credential = new ClientCredential(Startup.ClientId, Startup.ClientSecret);
result = await authContext.AcquireTokenSilentAsync(Startup.GraphResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
return null;
//HttpClient client = new HttpClient();
//HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/users/maluz@microsoft.com/photo/$value");
//request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
//HttpResponseMessage response = await client.SendAsync(request);

//if (response.IsSuccessStatusCode)
//{
// var source = await response.Content.ReadAsByteArrayAsync();
// return View();
//}
//else
//{
// //
// // If the call failed with access denied, then drop the current access token from the cache,
// // and show the user an error indicating they might need to sign-in again.
// //
// if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
// {

// //var todoTokens = authContext.TokenCache.ReadItems().Where(a => a.Resource == Startup.TodoListResourceId);
// //foreach (TokenCacheItem tci in todoTokens)
// // authContext.TokenCache.DeleteItem(tci);

// //ViewBag.ErrorMessage = "UnexpectedError";
// }
//}
}
catch (Exception)
{
//If get silent token fails:
return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme);
}


//return View("Error");
}
//private static async Task<IActionResult> CallMicrosoftGraph(HttpContext context)
//{
// AuthenticationResult result = null;

// try
// {
// string userObjectID = context.User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
// AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new SessionCache(userObjectID, context));
// ClientCredential credential = new ClientCredential(Startup.ClientId, Startup.ClientSecret);
// result = await authContext.AcquireTokenSilentAsync(Startup.GraphResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

// return null;
// }
// catch (Exception)
// {
// //If get silent token fails: retry the auth
// return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme);
// }
//}
}
}

0 comments on commit 84b1086

Please sign in to comment.