From 0d5482685b5b7cc585294877689085592d0f79de Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 12 Jul 2016 14:27:12 -0700 Subject: [PATCH] Update OpenIdConnect.AzureAdSample --- samples/OpenIdConnect.AzureAdSample/Startup.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/samples/OpenIdConnect.AzureAdSample/Startup.cs b/samples/OpenIdConnect.AzureAdSample/Startup.cs index fcfc7b4df0..05c073b46a 100644 --- a/samples/OpenIdConnect.AzureAdSample/Startup.cs +++ b/samples/OpenIdConnect.AzureAdSample/Startup.cs @@ -20,8 +20,6 @@ namespace OpenIdConnect.AzureAdSample { public class Startup { - private const string GraphResourceID = "https://graph.windows.net"; - public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() @@ -103,7 +101,20 @@ namespace OpenIdConnect.AzureAdSample 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 WriteHtmlAsync(context.Response,