public Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken) { ExternalAuthData.User eauser = new ExternalAuthData.User() { UserId = user.Id, GivenName = user.GivenName, SurName = user.SurName, Email = user.Email, UserName = user.Email, }; if (eauser.Claims == null) { eauser.Claims = new List <ExternalAuthData.Claim>(); } eauser.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "ProviderKey", ClaimValue = user.Id }); eauser.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "ProviderName", ClaimValue = user.AuthenticationProvider }); dbcontext.Users.Add(eauser); dbcontext.SaveChanges(); return(Task.FromResult(IdentityResult.Success)); }
public async Task <JsonResult> RegisterUser(string FirstName, string LastName, string Email) { var info = await SignInManager.GetExternalLoginInfoAsync(); ExternalAuthData.User user = new ExternalAuthData.User() { GivenName = FirstName, SurName = LastName, Email = Email, UserName = Email }; if (user.Claims == null) { user.Claims = new List <ExternalAuthData.Claim>(); } if (info.Principal.HasClaim(c => c.Type == ClaimTypes.NameIdentifier)) { user.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "ProviderKey", ClaimValue = info.Principal.FindFirstValue(ClaimTypes.NameIdentifier) }); } if (info.Principal.HasClaim(c => c.Type == ClaimTypes.NameIdentifier)) { user.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "ProviderName", ClaimValue = info.Principal.FindFirst(ClaimTypes.NameIdentifier).Issuer }); } if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Surname)) { user.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "Surname", ClaimValue = info.Principal.FindFirstValue(ClaimTypes.Surname) }); } if (info.Principal.HasClaim(c => c.Type == ClaimTypes.GivenName)) { user.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "GivenName", ClaimValue = info.Principal.FindFirstValue(ClaimTypes.GivenName) }); } if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email)) { user.Claims.Add(new ExternalAuthData.Claim() { ClaimType = "Email", ClaimValue = info.Principal.FindFirstValue(ClaimTypes.Email) }); } Context.Users.Add(user); Context.SaveChanges(); return(Json(string.Empty)); }