React to Auth API changes.

This commit is contained in:
Chris Ross 2015-04-24 12:03:19 -07:00
parent 69d42502a6
commit 2063ad5f67
2 changed files with 33 additions and 7 deletions

View File

@ -444,7 +444,7 @@ namespace MusicStore.Controllers
var appEnv = Context.RequestServices.GetService<IHostingEnvironment>();
if (appEnv.EnvironmentName.StartsWith("OpenIdConnect"))
{
Response.SignOut("OpenIdConnect");
Context.Authentication.SignOut("OpenIdConnect");
}
return RedirectToAction("Index", "Home");

View File

@ -29,10 +29,12 @@ namespace MusicStore.Controllers
.AddEntityFrameworkStores<MusicStoreContext>();
// IHttpContextAccessor is required for SignInManager, and UserManager
var context = new DefaultHttpContext();
context.SetFeature<IHttpAuthenticationFeature>(new HttpAuthenticationFeature() { Handler = new TestAuthHandler() });
services.AddInstance<IHttpContextAccessor>(
new HttpContextAccessor()
{
HttpContext = new TestHttpContext(),
HttpContext = context,
});
_serviceProvider = services.BuildServiceProvider();
@ -80,13 +82,37 @@ namespace MusicStore.Controllers
Assert.True(model.HasPassword);
}
private class TestHttpContext : DefaultHttpContext
private class TestAuthHandler : IAuthenticationHandler
{
public override Task<AuthenticationResult>
AuthenticateAsync(string authenticationScheme)
public void Authenticate(AuthenticateContext context)
{
return
Task.FromResult(new AuthenticateContext(authenticationScheme).Result);
context.NotAuthenticated();
}
public Task AuthenticateAsync(AuthenticateContext context)
{
context.NotAuthenticated();
return Task.FromResult(0);
}
public void Challenge(ChallengeContext context)
{
throw new NotImplementedException();
}
public void GetDescriptions(DescribeSchemesContext context)
{
throw new NotImplementedException();
}
public void SignIn(SignInContext context)
{
throw new NotImplementedException();
}
public void SignOut(SignOutContext context)
{
throw new NotImplementedException();
}
}
}