React to Auth API changes.
This commit is contained in:
parent
69d42502a6
commit
2063ad5f67
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue