React to forbid changes
This commit is contained in:
parent
d6a653145d
commit
273b25fb3a
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Security.Claims;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -58,29 +59,16 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
return _user;
|
return _user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task ChallengeAsync(AuthenticationProperties properties)
|
||||||
public Task ChallengeAsync(ChallengeContext context)
|
|
||||||
{
|
{
|
||||||
switch (context.Behavior)
|
// We would normally set the www-authenticate header here, but IIS does that for us.
|
||||||
{
|
_context.Response.StatusCode = 401;
|
||||||
case ChallengeBehavior.Automatic:
|
return TaskCache.CompletedTask;
|
||||||
// If there is a principal already, invoke the forbidden code path
|
}
|
||||||
if (GetUser() == null)
|
|
||||||
{
|
public Task ForbidAsync(AuthenticationProperties properties)
|
||||||
goto case ChallengeBehavior.Unauthorized;
|
{
|
||||||
}
|
_context.Response.StatusCode = 403;
|
||||||
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;
|
|
||||||
}
|
|
||||||
return TaskCache.CompletedTask;
|
return TaskCache.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,12 +79,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
|
||||||
return TaskCache.CompletedTask;
|
return TaskCache.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task SignInAsync(SignInContext context)
|
public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task SignOutAsync(SignOutContext context)
|
public Task SignOutAsync(AuthenticationProperties properties)
|
||||||
{
|
{
|
||||||
return TaskCache.CompletedTask;
|
return TaskCache.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="$(AspNetCoreVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue