Im trying to use AWS Cognito for my auth in a .Net Core MVC-app.

The login works fine, but none of my forms in the views work, they all give an error about my claims not containing "Name"-Claim.

I tried adding the name-claim manually but it still throws errors.

Any ideas how you configure this in .net core?

Error message:

InvalidOperationException: The provided identity of type 'System.Security.Claims.ClaimsIdentity' is marked IsAuthenticated = true but does not have a value for Name. By default, the antiforgery system requires that all authenticated identities have a unique Name. If it is not possible to provide a unique Name for this identity, consider extending IAntiforgeryAdditionalDataProvider by overriding the DefaultAntiforgeryAdditionalDataProvider or a custom type that can provide some form of unique identifier for the current user.

Startup-config:

```
services.AddAuthentication(options =>
            {
                //Sets Default Scheme.
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;

                //Must match the string for AddOAuth to set OAuth as default Challenge Scheme.
                options.DefaultChallengeScheme = "Cognito";
            })
               .AddCookie()
               .AddOAuth("Cognito", options =>
               {
                   options.ClientId = Configuration["Authentication:Cognito:ClientId"];
                   options.ClientSecret = Configuration["Authentication:Cognito:Secret"];
                   options.CallbackPath = new PathString("/sign-in");
                   options.AuthorizationEndpoint = "https://myauth.auth.eu-west-1.amazoncognito.com/oauth2/authorize";
                   options.TokenEndpoint = "https://myauth.auth.eu-west-1.amazoncognito.com/oauth2/token";
                   options.SaveTokens = true;
                   options.ClaimsIssuer = "https://cognito-idp.eu-west-1.amazonaws.com/ID";

                   options.Events = new OAuthEvents
                   {
                        //Adds Cognito id_token to Claims.
                        OnCreatingTicket = OnCreatingTicket
                   };
               });

```

Manually adding name-identifier:

```
private static Task OnCreatingTicket(OAuthCreatingTicketContext context)
        {
            var handler = new JwtSecurityTokenHandler();

            //Cognito stores user information and Claims in the id_token.
            var idToken = context.TokenResponse.Response["id_token"];
            var jwtToken = handler.ReadJwtToken(idToken.ToString());

            var appIdentity = new ClaimsIdentity(jwtToken.Claims);
            foreach (var item in appIdentity.Claims)
            {
                if (item.Type == "sub")
                { 
                    var name = new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", item.Value);
                    var name2 = new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", item.Value);
                    appIdentity.AddClaim(name);
                    appIdentity.AddClaim(name2);
                break;
                }
            }

            context.Principal.AddIdentity(appIdentity);
            return Task.CompletedTask;
        }

```