diff --git a/src/Microsoft.AspNet.Http.Core/Authentication/ChallengeContext.cs b/src/Microsoft.AspNet.Http.Core/Authentication/ChallengeContext.cs index 7b86337ccd..b47feedf45 100644 --- a/src/Microsoft.AspNet.Http.Core/Authentication/ChallengeContext.cs +++ b/src/Microsoft.AspNet.Http.Core/Authentication/ChallengeContext.cs @@ -4,33 +4,34 @@ using System; using System.Collections.Generic; using Microsoft.AspNet.Http.Authentication; -using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Http.Core.Authentication { public class ChallengeContext : IChallengeContext { - private List _accepted; + private bool _accepted; - public ChallengeContext([NotNull] IEnumerable authenticationSchemes, IDictionary properties) + public ChallengeContext(string authenticationScheme, IDictionary properties) { - AuthenticationSchemes = authenticationSchemes; + AuthenticationScheme = authenticationScheme; Properties = properties ?? new Dictionary(StringComparer.Ordinal); - _accepted = new List(); + + // The default Challenge with no scheme is always accepted + _accepted = string.IsNullOrEmpty(authenticationScheme); } - public IEnumerable AuthenticationSchemes { get; private set; } + public string AuthenticationScheme { get; private set; } public IDictionary Properties { get; private set; } - public IEnumerable Accepted + public bool Accepted { get { return _accepted; } } - public void Accept(string authenticationType, IDictionary description) + public void Accept() { - _accepted.Add(authenticationType); + _accepted = true; } } } diff --git a/src/Microsoft.AspNet.Http.Core/DefaultHttpResponse.cs b/src/Microsoft.AspNet.Http.Core/DefaultHttpResponse.cs index 0cb23010a0..1c91cd5a0c 100644 --- a/src/Microsoft.AspNet.Http.Core/DefaultHttpResponse.cs +++ b/src/Microsoft.AspNet.Http.Core/DefaultHttpResponse.cs @@ -130,22 +130,20 @@ namespace Microsoft.AspNet.Http.Core Headers.Set(HeaderNames.Location, location); } - public override void Challenge(AuthenticationProperties properties, [NotNull] IEnumerable authenticationSchemes) + public override void Challenge(AuthenticationProperties properties, string authenticationScheme) { HttpResponseFeature.StatusCode = 401; var handler = HttpAuthenticationFeature.Handler; - var challengeContext = new ChallengeContext(authenticationSchemes, properties == null ? null : properties.Dictionary); + var challengeContext = new ChallengeContext(authenticationScheme, properties == null ? null : properties.Dictionary); if (handler != null) { handler.Challenge(challengeContext); } - // Verify all types ack'd - IEnumerable leftovers = authenticationSchemes.Except(challengeContext.Accepted); - if (leftovers.Any()) + if (!challengeContext.Accepted) { - throw new InvalidOperationException("The following authentication types were not accepted: " + string.Join(", ", leftovers)); + throw new InvalidOperationException("The following authentication type was not accepted: " + authenticationScheme); } } diff --git a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs index 3c6f2058de..26a90fefb2 100644 --- a/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs +++ b/src/Microsoft.AspNet.Http.Interfaces/Authentication/IChallengeContext.cs @@ -7,9 +7,9 @@ namespace Microsoft.AspNet.Http.Authentication { public interface IChallengeContext { - IEnumerable AuthenticationSchemes {get;} - IDictionary Properties {get;} + string AuthenticationScheme { get; } + IDictionary Properties { get; } - void Accept(string authenticationType, IDictionary description); + void Accept(); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Http/HttpResponse.cs b/src/Microsoft.AspNet.Http/HttpResponse.cs index 5fd8e099e0..97c0a63e50 100644 --- a/src/Microsoft.AspNet.Http/HttpResponse.cs +++ b/src/Microsoft.AspNet.Http/HttpResponse.cs @@ -38,40 +38,20 @@ namespace Microsoft.AspNet.Http public virtual void Challenge() { - Challenge(new string[0]); + Challenge(properties: null, authenticationScheme: null); } public virtual void Challenge(AuthenticationProperties properties) { - Challenge(properties, new string[0]); + Challenge(properties, ""); } public virtual void Challenge(string authenticationScheme) { - Challenge(new[] { authenticationScheme }); + Challenge(properties: null, authenticationScheme: authenticationScheme); } - public virtual void Challenge(AuthenticationProperties properties, string authenticationScheme) - { - Challenge(properties, new[] { authenticationScheme }); - } - - public virtual void Challenge(params string[] authenticationSchemes) - { - Challenge((IEnumerable)authenticationSchemes); - } - - public virtual void Challenge(IEnumerable authenticationSchemes) - { - Challenge(properties: null, authenticationSchemes: authenticationSchemes); - } - - public virtual void Challenge(AuthenticationProperties properties, params string[] authenticationSchemes) - { - Challenge(properties, (IEnumerable)authenticationSchemes); - } - - public abstract void Challenge(AuthenticationProperties properties, IEnumerable authenticationSchemes); + public abstract void Challenge(AuthenticationProperties properties, string authenticationScheme); public abstract void SignIn(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties = null);