If you bypass authentication, how do you distinguish between internal or public requests for api? This causes a security error. Therefore, you should not bypass authentication.
If you use openidconnect authentication in the mvc application, you can set SaveTokens=true . It allows you to store the access token in a cookie. When you call api in mvc action, you can send this access_token in api.
Another way to use two different intermediate authentication programs is one for internal sharing (this is hard to implement).
I would go with the first approach.
Update
To achieve your goal, it comes to my mind a difficult way, but I'm not sure if this is a good way:
Create a filter provider:
public class EncFilterProvider : IFilterProvider { public int Order { get { return -1500; } } public void OnProvidersExecuted(FilterProviderContext context) { } public void OnProvidersExecuting(FilterProviderContext context) {
Then register it conditionally based on the configuration value
public void ConfigureServices(IServiceCollection services) { if(config["servermode"] = "internal") { services.AddScoped<IFilterProvider, EncFilterProvider>(); } }
source share