React to auth changes

This commit is contained in:
Hao Kung 2015-03-16 16:46:56 -07:00
parent 4883cfe40d
commit efc5ea9b5d
2 changed files with 17 additions and 6 deletions

View File

@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Server.WebListener
foreach (var authType in ListEnabledAuthSchemes()) foreach (var authType in ListEnabledAuthSchemes())
{ {
string authScheme = authType.ToString(); string authScheme = authType.ToString();
if (context.AuthenticationSchemes.Contains(authScheme, StringComparer.Ordinal)) if (string.Equals(authScheme, context.AuthenticationScheme, StringComparison.Ordinal))
{ {
if (identity != null && identity.IsAuthenticated if (identity != null && identity.IsAuthenticated
&& string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal)) && string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal))
@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Server.WebListener
} }
else else
{ {
context.NotAuthenticated(authScheme, properties: null, description: GetDescription(authScheme)); context.NotAuthenticated();
} }
} }
} }

View File

@ -262,8 +262,11 @@ namespace Microsoft.AspNet.Server.WebListener
var context = new DefaultHttpContext((IFeatureCollection)env); var context = new DefaultHttpContext((IFeatureCollection)env);
Assert.NotNull(context.User); Assert.NotNull(context.User);
Assert.False(context.User.Identity.IsAuthenticated); Assert.False(context.User.Identity.IsAuthenticated);
var authResults = context.Authenticate(authTypeList); foreach (var scheme in authTypeList)
Assert.False(authResults.Any()); {
var authResults = context.Authenticate(scheme);
Assert.Null(authResults.Principal);
}
return Task.FromResult(0); return Task.FromResult(0);
})) }))
{ {
@ -289,8 +292,16 @@ namespace Microsoft.AspNet.Server.WebListener
var context = new DefaultHttpContext((IFeatureCollection)env); var context = new DefaultHttpContext((IFeatureCollection)env);
Assert.NotNull(context.User); Assert.NotNull(context.User);
Assert.True(context.User.Identity.IsAuthenticated); Assert.True(context.User.Identity.IsAuthenticated);
var authResults = context.Authenticate(authTypeList); var count = 0;
Assert.Equal(1, authResults.Count()); foreach (var scheme in authTypeList)
{
var authResults = context.Authenticate(scheme);
if (authResults.Principal != null)
{
count++;
}
}
Assert.Equal(1, count);
return Task.FromResult(0); return Task.FromResult(0);
})) }))
{ {