Skip to content

Commit d072508

Browse files
TratcherDylanDmitri
authored andcommitted
Add new Negotiate Auth handler (#9831)
1 parent 9c84558 commit d072508

File tree

54 files changed

+3287
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3287
-7
lines changed

eng/ProjectReferences.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.Google" ProjectPath="$(RepoRoot)src\Security\Authentication\Google\src\Microsoft.AspNetCore.Authentication.Google.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\Google\ref\Microsoft.AspNetCore.Authentication.Google.csproj" />
6464
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.JwtBearer" ProjectPath="$(RepoRoot)src\Security\Authentication\JwtBearer\src\Microsoft.AspNetCore.Authentication.JwtBearer.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\JwtBearer\ref\Microsoft.AspNetCore.Authentication.JwtBearer.csproj" />
6565
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" ProjectPath="$(RepoRoot)src\Security\Authentication\MicrosoftAccount\src\Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\MicrosoftAccount\ref\Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj" />
66+
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.Negotiate" ProjectPath="$(RepoRoot)src\Security\Authentication\Negotiate\src\Microsoft.AspNetCore.Authentication.Negotiate.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\Negotiate\ref\Microsoft.AspNetCore.Authentication.Negotiate.csproj" />
6667
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.OAuth" ProjectPath="$(RepoRoot)src\Security\Authentication\OAuth\src\Microsoft.AspNetCore.Authentication.OAuth.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\OAuth\ref\Microsoft.AspNetCore.Authentication.OAuth.csproj" />
6768
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" ProjectPath="$(RepoRoot)src\Security\Authentication\OpenIdConnect\src\Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\OpenIdConnect\ref\Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj" />
6869
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Authentication.Twitter" ProjectPath="$(RepoRoot)src\Security\Authentication\Twitter\src\Microsoft.AspNetCore.Authentication.Twitter.csproj" RefProjectPath="$(RepoRoot)src\Security\Authentication\Twitter\ref\Microsoft.AspNetCore.Authentication.Twitter.csproj" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- This file is automatically generated. -->
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFrameworks>netcoreapp3.0</TargetFrameworks>
5+
</PropertyGroup>
6+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
7+
<Compile Include="Microsoft.AspNetCore.Authentication.Negotiate.netcoreapp3.0.cs" />
8+
<Reference Include="Microsoft.AspNetCore.Authentication" />
9+
<Reference Include="Microsoft.AspNetCore.Connections.Abstractions" />
10+
</ItemGroup>
11+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNetCore.Authentication.Negotiate
5+
{
6+
public partial class AuthenticatedContext : Microsoft.AspNetCore.Authentication.ResultContext<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions>
7+
{
8+
public AuthenticatedContext(Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme, Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions options) : base (default(Microsoft.AspNetCore.Http.HttpContext), default(Microsoft.AspNetCore.Authentication.AuthenticationScheme), default(Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions)) { }
9+
}
10+
public partial class AuthenticationFailedContext : Microsoft.AspNetCore.Authentication.RemoteAuthenticationContext<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions>
11+
{
12+
public AuthenticationFailedContext(Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme, Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions options) : base (default(Microsoft.AspNetCore.Http.HttpContext), default(Microsoft.AspNetCore.Authentication.AuthenticationScheme), default(Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions), default(Microsoft.AspNetCore.Authentication.AuthenticationProperties)) { }
13+
public System.Exception Exception { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
14+
}
15+
public partial class ChallengeContext : Microsoft.AspNetCore.Authentication.PropertiesContext<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions>
16+
{
17+
public ChallengeContext(Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme, Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions options, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) : base (default(Microsoft.AspNetCore.Http.HttpContext), default(Microsoft.AspNetCore.Authentication.AuthenticationScheme), default(Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions), default(Microsoft.AspNetCore.Authentication.AuthenticationProperties)) { }
18+
public bool Handled { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
19+
public void HandleResponse() { }
20+
}
21+
public static partial class NegotiateDefaults
22+
{
23+
public const string AuthenticationScheme = "Negotiate";
24+
}
25+
public partial class NegotiateEvents
26+
{
27+
public NegotiateEvents() { }
28+
public System.Func<Microsoft.AspNetCore.Authentication.Negotiate.AuthenticatedContext, System.Threading.Tasks.Task> OnAuthenticated { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
29+
public System.Func<Microsoft.AspNetCore.Authentication.Negotiate.AuthenticationFailedContext, System.Threading.Tasks.Task> OnAuthenticationFailed { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
30+
public System.Func<Microsoft.AspNetCore.Authentication.Negotiate.ChallengeContext, System.Threading.Tasks.Task> OnChallenge { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
31+
public virtual System.Threading.Tasks.Task Authenticated(Microsoft.AspNetCore.Authentication.Negotiate.AuthenticatedContext context) { throw null; }
32+
public virtual System.Threading.Tasks.Task AuthenticationFailed(Microsoft.AspNetCore.Authentication.Negotiate.AuthenticationFailedContext context) { throw null; }
33+
public virtual System.Threading.Tasks.Task Challenge(Microsoft.AspNetCore.Authentication.Negotiate.ChallengeContext context) { throw null; }
34+
}
35+
public partial class NegotiateHandler : Microsoft.AspNetCore.Authentication.AuthenticationHandler<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions>, Microsoft.AspNetCore.Authentication.IAuthenticationHandler, Microsoft.AspNetCore.Authentication.IAuthenticationRequestHandler
36+
{
37+
public NegotiateHandler(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions> options, Microsoft.Extensions.Logging.ILoggerFactory logger, System.Text.Encodings.Web.UrlEncoder encoder, Microsoft.AspNetCore.Authentication.ISystemClock clock) : base (default(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions>), default(Microsoft.Extensions.Logging.ILoggerFactory), default(System.Text.Encodings.Web.UrlEncoder), default(Microsoft.AspNetCore.Authentication.ISystemClock)) { }
38+
protected new Microsoft.AspNetCore.Authentication.Negotiate.NegotiateEvents Events { get { throw null; } set { } }
39+
protected override System.Threading.Tasks.Task<object> CreateEventsAsync() { throw null; }
40+
[System.Diagnostics.DebuggerStepThroughAttribute]
41+
protected override System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult> HandleAuthenticateAsync() { throw null; }
42+
[System.Diagnostics.DebuggerStepThroughAttribute]
43+
protected override System.Threading.Tasks.Task HandleChallengeAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; }
44+
[System.Diagnostics.DebuggerStepThroughAttribute]
45+
public System.Threading.Tasks.Task<bool> HandleRequestAsync() { throw null; }
46+
}
47+
public partial class NegotiateOptions : Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions
48+
{
49+
public NegotiateOptions() { }
50+
public new Microsoft.AspNetCore.Authentication.Negotiate.NegotiateEvents Events { get { throw null; } set { } }
51+
public bool PersistKerberosCredentials { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
52+
public bool PersistNtlmCredentials { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
53+
}
54+
}
55+
namespace Microsoft.Extensions.DependencyInjection
56+
{
57+
public static partial class NegotiateExtensions
58+
{
59+
public static Microsoft.AspNetCore.Authentication.AuthenticationBuilder AddNegotiate(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder builder) { throw null; }
60+
public static Microsoft.AspNetCore.Authentication.AuthenticationBuilder AddNegotiate(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder builder, System.Action<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions> configureOptions) { throw null; }
61+
public static Microsoft.AspNetCore.Authentication.AuthenticationBuilder AddNegotiate(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder builder, string authenticationScheme, System.Action<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions> configureOptions) { throw null; }
62+
public static Microsoft.AspNetCore.Authentication.AuthenticationBuilder AddNegotiate(this Microsoft.AspNetCore.Authentication.AuthenticationBuilder builder, string authenticationScheme, string displayName, System.Action<Microsoft.AspNetCore.Authentication.Negotiate.NegotiateOptions> configureOptions) { throw null; }
63+
}
64+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Reference Include="Microsoft.AspNetCore" />
10+
<Reference Include="Microsoft.AspNetCore.Authentication.Negotiate" />
11+
<Reference Include="Microsoft.AspNetCore.Authorization" />
12+
<Reference Include="Microsoft.Extensions.Hosting" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.Extensions.Hosting;
6+
7+
namespace NegotiateAuthSample
8+
{
9+
public class Program
10+
{
11+
public static void Main(string[] args)
12+
{
13+
CreateHostBuilder(args).Build().Run();
14+
}
15+
16+
public static IHostBuilder CreateHostBuilder(string[] args) =>
17+
Host.CreateDefaultBuilder(args)
18+
.ConfigureWebHostDefaults(webBuilder =>
19+
{
20+
webBuilder.UseStartup<Startup>();
21+
});
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:6449",
7+
"sslPort": 44369
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"NegotiateAuthSample": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "https://localhost:5001;http://localhost:5000"
25+
}
26+
}
27+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Authentication.Negotiate;
6+
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.Http;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Hosting;
11+
12+
namespace NegotiateAuthSample
13+
{
14+
public class Startup
15+
{
16+
public void ConfigureServices(IServiceCollection services)
17+
{
18+
services.AddAuthorization(options =>
19+
{
20+
options.FallbackPolicy = options.DefaultPolicy;
21+
});
22+
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
23+
.AddNegotiate();
24+
}
25+
26+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
27+
{
28+
app.UseDeveloperExceptionPage();
29+
app.UseAuthentication();
30+
app.UseAuthorization();
31+
app.Run(HandleRequest);
32+
}
33+
34+
public async Task HandleRequest(HttpContext context)
35+
{
36+
var user = context.User.Identity;
37+
await context.Response.WriteAsync($"Authenticated? {user.IsAuthenticated}, Name: {user.Name}, Protocol: {context.Request.Protocol}");
38+
}
39+
}
40+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information",
7+
"Microsoft.AspNetCore.Authentication": "Debug"
8+
}
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Warning",
5+
"Microsoft.Hosting.Lifetime": "Information"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
5+
6+
namespace Microsoft.AspNetCore.Authentication.Negotiate
7+
{
8+
/// <summary>
9+
/// State for the Authenticated event.
10+
/// </summary>
11+
public class AuthenticatedContext : ResultContext<NegotiateOptions>
12+
{
13+
/// <summary>
14+
/// Creates a new <see cref="AuthenticatedContext"/>.
15+
/// </summary>
16+
/// <param name="context"></param>
17+
/// <param name="scheme"></param>
18+
/// <param name="options"></param>
19+
public AuthenticatedContext(
20+
HttpContext context,
21+
AuthenticationScheme scheme,
22+
NegotiateOptions options)
23+
: base(context, scheme, options) { }
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.AspNetCore.Http;
6+
7+
namespace Microsoft.AspNetCore.Authentication.Negotiate
8+
{
9+
/// <summary>
10+
/// State for the AuthenticationFailed event.
11+
/// </summary>
12+
public class AuthenticationFailedContext : RemoteAuthenticationContext<NegotiateOptions>
13+
{
14+
/// <summary>
15+
/// Creates a <see cref="AuthenticationFailedContext"/>.
16+
/// </summary>
17+
/// <param name="context"></param>
18+
/// <param name="scheme"></param>
19+
/// <param name="options"></param>
20+
public AuthenticationFailedContext(
21+
HttpContext context,
22+
AuthenticationScheme scheme,
23+
NegotiateOptions options)
24+
: base(context, scheme, options, properties: null) { }
25+
26+
/// <summary>
27+
/// The exception that occured while processing the authentication.
28+
/// </summary>
29+
public Exception Exception { get; set; }
30+
}
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.AspNetCore.Http;
6+
7+
namespace Microsoft.AspNetCore.Authentication.Negotiate
8+
{
9+
/// <summary>
10+
/// State for the Challenge event.
11+
/// </summary>
12+
public class ChallengeContext : PropertiesContext<NegotiateOptions>
13+
{
14+
/// <summary>
15+
/// Creates a new <see cref="ChallengeContext"/>.
16+
/// </summary>
17+
/// <param name="context"></param>
18+
/// <param name="scheme"></param>
19+
/// <param name="options"></param>
20+
/// <param name="properties"></param>
21+
public ChallengeContext(
22+
HttpContext context,
23+
AuthenticationScheme scheme,
24+
NegotiateOptions options,
25+
AuthenticationProperties properties)
26+
: base(context, scheme, options, properties) { }
27+
28+
/// <summary>
29+
/// If true, will skip any default logic for this challenge.
30+
/// </summary>
31+
public bool Handled { get; private set; }
32+
33+
/// <summary>
34+
/// Skips any default logic for this challenge.
35+
/// </summary>
36+
public void HandleResponse() => Handled = true;
37+
}
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.AspNetCore.Authentication.Negotiate
8+
{
9+
/// <summary>
10+
/// Specifies events which the <see cref="NegotiateHandler"/> invokes to enable developer control over the authentication process.
11+
/// </summary>
12+
public class NegotiateEvents
13+
{
14+
/// <summary>
15+
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
16+
/// </summary>
17+
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => Task.CompletedTask;
18+
19+
/// <summary>
20+
/// Invoked after the authentication is complete and a ClaimsIdentity has been generated.
21+
/// </summary>
22+
public Func<AuthenticatedContext, Task> OnAuthenticated { get; set; } = context => Task.CompletedTask;
23+
24+
/// <summary>
25+
/// Invoked before a challenge is sent back to the caller.
26+
/// </summary>
27+
public Func<ChallengeContext, Task> OnChallenge { get; set; } = context => Task.CompletedTask;
28+
29+
/// <summary>
30+
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
31+
/// </summary>
32+
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
33+
34+
/// <summary>
35+
/// Invoked after the authentication is complete and a ClaimsIdentity has been generated.
36+
/// </summary>
37+
public virtual Task Authenticated(AuthenticatedContext context) => OnAuthenticated(context);
38+
39+
/// <summary>
40+
/// Invoked before a challenge is sent back to the caller.
41+
/// </summary>
42+
public virtual Task Challenge(ChallengeContext context) => OnChallenge(context);
43+
}
44+
}

0 commit comments

Comments
 (0)