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>();
|
var appEnv = Context.RequestServices.GetService<IHostingEnvironment>();
|
||||||
if (appEnv.EnvironmentName.StartsWith("OpenIdConnect"))
|
if (appEnv.EnvironmentName.StartsWith("OpenIdConnect"))
|
||||||
{
|
{
|
||||||
Response.SignOut("OpenIdConnect");
|
Context.Authentication.SignOut("OpenIdConnect");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction("Index", "Home");
|
return RedirectToAction("Index", "Home");
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,12 @@ namespace MusicStore.Controllers
|
||||||
.AddEntityFrameworkStores<MusicStoreContext>();
|
.AddEntityFrameworkStores<MusicStoreContext>();
|
||||||
|
|
||||||
// IHttpContextAccessor is required for SignInManager, and UserManager
|
// IHttpContextAccessor is required for SignInManager, and UserManager
|
||||||
|
var context = new DefaultHttpContext();
|
||||||
|
context.SetFeature<IHttpAuthenticationFeature>(new HttpAuthenticationFeature() { Handler = new TestAuthHandler() });
|
||||||
services.AddInstance<IHttpContextAccessor>(
|
services.AddInstance<IHttpContextAccessor>(
|
||||||
new HttpContextAccessor()
|
new HttpContextAccessor()
|
||||||
{
|
{
|
||||||
HttpContext = new TestHttpContext(),
|
HttpContext = context,
|
||||||
});
|
});
|
||||||
|
|
||||||
_serviceProvider = services.BuildServiceProvider();
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
|
@ -80,13 +82,37 @@ namespace MusicStore.Controllers
|
||||||
Assert.True(model.HasPassword);
|
Assert.True(model.HasPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestHttpContext : DefaultHttpContext
|
private class TestAuthHandler : IAuthenticationHandler
|
||||||
{
|
{
|
||||||
public override Task<AuthenticationResult>
|
public void Authenticate(AuthenticateContext context)
|
||||||
AuthenticateAsync(string authenticationScheme)
|
|
||||||
{
|
{
|
||||||
return
|
context.NotAuthenticated();
|
||||||
Task.FromResult(new AuthenticateContext(authenticationScheme).Result);
|
}
|
||||||
|
|
||||||
|
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