I upgraded & ran into this issue where `UseIdentity()` is not available in StartUp.cs when building application (ApplicationBuilder).
The webservice use it so what is the recommended fix? The MVC Controller have attribute that checked for valid Identity. The `OnAuthorizationAsync` in Filter Attribute class do check for active Identity. This is where custom basic authentication pass in the login.
// Startup.cs
public void Configure(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory, IServiceProvider serviceProvider)
{
// Webservice API access.
applicationBuilder.UseWhen(context =>
!context.Request.Path.StartsWithSegments(new PathString("/api/v1")),
b => b.UseIdentity()
);
applicationBuilder.UseWhen(context =>
!context.Request.Path.StartsWithSegments(new PathString("/api/v1")),
b => b.UseAuthentication()
);
}
// MerchantsV1Controller.cs
[TypeFilter(typeof(AuthorizeWithNoChallengeFilterAttribute))]
public class MerchantsV1Controller : Controller
{
}
// AuthorizeWithNoChallengeFilterAttribute.cs
public class AuthorizeWithNoChallengeFilterAttribute : IAsyncAuthorizationFilter
{
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
if (!context.HttpContext.User.Identity.IsAuthenticated)
context.Result = new UnauthorizedResult();
await Task.CompletedTask;
}
}