From 273b25fb3a2967834b2603f8b3c71cc572d06e13 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 25 May 2017 18:37:27 -0700 Subject: [PATCH] React to forbid changes --- .../AuthenticationHandler.cs | 36 +++++++------------ ...NetCore.Server.IISIntegration.Tests.csproj | 1 - 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/AuthenticationHandler.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/AuthenticationHandler.cs index ead59b0cb4..050b40e283 100644 --- a/src/Microsoft.AspNetCore.Server.IISIntegration/AuthenticationHandler.cs +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/AuthenticationHandler.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Security.Claims; using System.Globalization; using System.Security.Principal; using System.Threading.Tasks; @@ -58,29 +59,16 @@ namespace Microsoft.AspNetCore.Server.IISIntegration return _user; } - - public Task ChallengeAsync(ChallengeContext context) + public Task ChallengeAsync(AuthenticationProperties properties) { - switch (context.Behavior) - { - case ChallengeBehavior.Automatic: - // If there is a principal already, invoke the forbidden code path - if (GetUser() == null) - { - goto case ChallengeBehavior.Unauthorized; - } - else - { - goto case ChallengeBehavior.Forbidden; - } - case ChallengeBehavior.Unauthorized: - context.HttpContext.Response.StatusCode = 401; - // We would normally set the www-authenticate header here, but IIS does that for us. - break; - case ChallengeBehavior.Forbidden: - context.HttpContext.Response.StatusCode = 403; - break; - } + // We would normally set the www-authenticate header here, but IIS does that for us. + _context.Response.StatusCode = 401; + return TaskCache.CompletedTask; + } + + public Task ForbidAsync(AuthenticationProperties properties) + { + _context.Response.StatusCode = 403; return TaskCache.CompletedTask; } @@ -91,12 +79,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration return TaskCache.CompletedTask; } - public Task SignInAsync(SignInContext context) + public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties) { throw new NotSupportedException(); } - public Task SignOutAsync(SignOutContext context) + public Task SignOutAsync(AuthenticationProperties properties) { return TaskCache.CompletedTask; } diff --git a/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tests.csproj b/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tests.csproj index 32537f1e0d..a870275e4f 100644 --- a/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tests.csproj +++ b/test/Microsoft.AspNetCore.Server.IISIntegration.Tests/Microsoft.AspNetCore.Server.IISIntegration.Tests.csproj @@ -12,7 +12,6 @@ -