diff --git a/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticateResult.cs b/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticateResult.cs
deleted file mode 100644
index 28060a24e2..0000000000
--- a/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticateResult.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-
-using System.Security.Claims;
-using Microsoft.Framework.Internal;
-
-namespace Microsoft.AspNet.Http.Authentication
-{
- ///
- /// Acts as the return value from calls to the IAuthenticationManager's AuthenticeAsync methods.
- ///
- public class AuthenticationResult
- {
- ///
- /// Create an instance of the result object
- ///
- /// Assigned to Identity. May be null.
- /// Assigned to Properties. Contains extra information carried along with the identity.
- /// Assigned to Description. Contains information describing the authentication provider.
- public AuthenticationResult(ClaimsPrincipal principal, [NotNull] AuthenticationProperties properties, [NotNull] AuthenticationDescription description)
- {
- Principal = principal;
- Properties = properties;
- Description = description;
- }
-
- ///
- /// Contains the claims that were authenticated by the given AuthenticationScheme. If the authentication
- /// scheme was not successful the Identity property will be null.
- ///
- public ClaimsPrincipal Principal { get; private set; }
-
- ///
- /// Contains extra values that were provided with the original SignIn call.
- ///
- public AuthenticationProperties Properties { get; private set; }
-
- ///
- /// Contains description properties for the middleware authentication type in general. Does not
- /// vary per request.
- ///
- public AuthenticationDescription Description { get; private set; }
- }
-}
diff --git a/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs b/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs
index 331c4c8fe1..e10e081717 100644
--- a/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs
+++ b/src/Microsoft.AspNet.Http.Abstractions/Authentication/AuthenticationManager.cs
@@ -4,6 +4,8 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
+using Microsoft.AspNet.Http.Features.Authentication;
+using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Http.Authentication
{
@@ -11,41 +13,61 @@ namespace Microsoft.AspNet.Http.Authentication
{
public abstract IEnumerable GetAuthenticationSchemes();
- public abstract AuthenticationResult Authenticate(string authenticationScheme);
+ public abstract Task AuthenticateAsync([NotNull] AuthenticateContext context);
- public abstract Task AuthenticateAsync(string authenticationScheme);
-
- public virtual void Challenge()
+ public virtual async Task AuthenticateAsync([NotNull] string authenticationScheme)
{
- Challenge(authenticationScheme: null, properties: null);
+ var context = new AuthenticateContext(authenticationScheme);
+ await AuthenticateAsync(context);
+ return context.Principal;
}
- public virtual void Challenge(AuthenticationProperties properties)
+ public virtual Task ChallengeAsync()
{
- Challenge(authenticationScheme: null, properties: properties);
+ return ChallengeAsync(properties: null);
}
- public virtual void Challenge(string authenticationScheme)
+ public virtual Task ChallengeAsync(AuthenticationProperties properties)
{
- Challenge(authenticationScheme: authenticationScheme, properties: null);
+ return ChallengeAsync(authenticationScheme: string.Empty, properties: properties);
}
- public abstract void Challenge(string authenticationScheme, AuthenticationProperties properties);
-
- public void SignIn(string authenticationScheme, ClaimsPrincipal principal)
+ public virtual Task ChallengeAsync([NotNull] string authenticationScheme)
{
- SignIn(authenticationScheme, principal, properties: null);
+ return ChallengeAsync(authenticationScheme: authenticationScheme, properties: null);
}
- public abstract void SignIn(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties);
-
- public virtual void SignOut()
+ // Leave it up to authentication handler to do the right thing for the challenge
+ public virtual Task ChallengeAsync([NotNull] string authenticationScheme, AuthenticationProperties properties)
{
- SignOut(authenticationScheme: null, properties: null);
+ return ChallengeAsync(authenticationScheme, properties, ChallengeBehavior.Automatic);
}
- public abstract void SignOut(string authenticationScheme);
+ public virtual Task SignInAsync([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal)
+ {
+ return SignInAsync(authenticationScheme, principal, properties: null);
+ }
- public abstract void SignOut(string authenticationScheme, AuthenticationProperties properties);
+ public virtual Task ForbidAsync([NotNull] string authenticationScheme)
+ {
+ return ForbidAsync(authenticationScheme, properties: null);
+ }
+
+ // Deny access (typically a 403)
+ public virtual Task ForbidAsync([NotNull] string authenticationScheme, AuthenticationProperties properties)
+ {
+ return ChallengeAsync(authenticationScheme, properties, ChallengeBehavior.Forbidden);
+ }
+
+ public abstract Task ChallengeAsync([NotNull] string authenticationScheme, AuthenticationProperties properties, ChallengeBehavior behavior);
+
+ public abstract Task SignInAsync([NotNull] string authenticationScheme, [NotNull] ClaimsPrincipal principal, AuthenticationProperties properties);
+
+ public virtual Task SignOutAsync([NotNull] string authenticationScheme)
+ {
+ return SignOutAsync(authenticationScheme, properties: null);
+ }
+
+ public abstract Task SignOutAsync([NotNull] string authenticationScheme, AuthenticationProperties properties);
}
}
diff --git a/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs b/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs
index a0a92fb823..914e9604c9 100644
--- a/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs
+++ b/src/Microsoft.AspNet.Http.Abstractions/HttpResponse.cs
@@ -3,11 +3,20 @@
using System;
using System.IO;
+using System.Threading.Tasks;
+using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Http
{
public abstract class HttpResponse
{
+ private static readonly Func