To allow security sharing by other components that can be hosted on OWIN.
ASP.NET MVC 5 has applied a new security feature based on the OWIN authentication middleware.
Now, if we apply this logic in our MVC5 application, we will find that we do have added our authentication cookie, however, as MVC5 follows the OWIN middleware, it has no way to understand our user is authenticated or not in Request.IsAuthenticated.
A user is authenticated by calling AuthenticationManager.SignIn, to understand more details in it, we can have a look in the Katana Project’s AuthenticationManager.
Solution
So, in order to SignIn a user, we just have to call the method AuthenticationManager.SignIn, which, request us to have a Claims base Identity implementation. By having a look in the Katana Project, we can easily create one for ourselves, below is an example of the rewrite of the SignInAsync:
The reason of this error occurs is because we have now implemented our own claims for our user, and we therefore need to tell AntiForgery how to identify our user’s uniqueless based on our claim. The solution is as easy as adding the following line in Global.asax.cs
Note that I use ClaimTypes.Name because I have added the claims using ClaimsIdentity.DefaultNameClaimType, we can use a list of predefined claim types by the ClaimTypes class defined in .NET too.
A claim of type ‘http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier’ or ‘http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider’ was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.