How do I redirect requests coming to some path (web site) to login page but respond with unauthorized to requests coming to another path (API paths)? As I understand AutomaticChallenge changes this behavior for all the web app. But how to make it conditional?
I use OpenIddict which is OpenId Connect Server configuration library. And, in general, clients are mobile apps. However it would be nice to have a web site like behavior for some controllers that return views.
Startup code looks this way:
// Add a middleware used to validate access
// tokens and protect the API endpoints.
app.UseOAuthValidation();
app.UseCsp(options => options.DefaultSources(directive => directive.Self())
.ImageSources(directive => directive.Self()
.CustomSources("*"))
.ScriptSources(directive => directive.Self()
.UnsafeInline())
.StyleSources(directive => directive.Self()
.UnsafeInline()));
app.UseXContentTypeOptions();
app.UseXfo(options => options.Deny());
app.UseXXssProtection(options => options.EnabledWithBlockMode());
app.UseIdentity();
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseTwitterAuthentication(...);
app.UseFacebookAuthentication(...);
app.UseGoogleAuthentication(...);
app.UseSession();
app.UseOpenIddict();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseSwagger();
app.UseSwaggerUi();