I have this solution:
I need to authenticate on the ASP.NET MVC site and on the Web Api 2.0 just once (I mean that I do not have to check if username and password is correct on MVC site and then check them on Web Api again).
I honestly think that AngularJS and ASP.NET MVC is not a good couple. But, that's it! ASP.NET MVC site and Web Api could be on different servers.
In this moment I can authenticate just on MVC Application, I cannot "pass" the authentication on the web api. I am using the default code of the ASP.NET Identity. So, im my startup
class I have:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
So, how can I be "automatically" authenticated on web api, once I have been authenticated on asp.net mvc?
Thank you
UPDATE
I have updated the image. In this moment I do some requests from MVC application. But those requests do not need authentication. Some other requests arrive from angularjs and here I need authentication. In this moment I authenticate the user in the MVC application.