Update OpenIdConnect.AzureAdSample

This commit is contained in:
Troy Dai 2016-07-12 14:27:12 -07:00
parent 59a86c17e2
commit 0d5482685b
1 changed files with 14 additions and 3 deletions

View File

@ -20,8 +20,6 @@ namespace OpenIdConnect.AzureAdSample
{ {
public class Startup public class Startup
{ {
private const string GraphResourceID = "https://graph.windows.net";
public Startup(IHostingEnvironment env) public Startup(IHostingEnvironment env)
{ {
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
@ -103,7 +101,20 @@ namespace OpenIdConnect.AzureAdSample
app.Run(async context => app.Run(async context =>
{ {
if (context.Request.Path.Equals("/signout")) if (context.Request.Path.Equals("/signin"))
{
if (context.User.Identities.Any(identity => identity.IsAuthenticated))
{
// User has already signed in
context.Response.Redirect("/");
return;
}
await context.Authentication.ChallengeAsync(
OpenIdConnectDefaults.AuthenticationScheme,
new AuthenticationProperties { RedirectUri = "/" });
}
else if (context.Request.Path.Equals("/signout"))
{ {
await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await WriteHtmlAsync(context.Response, await WriteHtmlAsync(context.Response,