public async Task <ActionResult> Index(ExternalRegistrationModel model) { var ctx = Request.GetOwinContext(); var partial_user = await ctx.Environment.GetIdentityServerPartialLoginAsync(); if (partial_user == null) { return(View("Error")); } if (ModelState.IsValid) { // update the "database" for our users with the registration data var subject = partial_user.GetSubjectId(); var db_user = ExternalRegistrationUserService.Users.Single(x => x.Subject == subject); db_user.Claims.Add(new Claim(Constants.ClaimTypes.GivenName, model.First)); db_user.Claims.Add(new Claim(Constants.ClaimTypes.FamilyName, model.Last)); // replace the name captured from the external identity provider var nameClaim = db_user.Claims.Single(x => x.Type == Constants.ClaimTypes.Name); db_user.Claims.Remove(nameClaim); nameClaim = new Claim(Constants.ClaimTypes.Name, model.First + " " + model.Last); db_user.Claims.Add(nameClaim); // mark user as registered db_user.IsRegistered = true; // this replaces the name issued in the partial signin cookie // the reason for doing is so when we redriect back to IdSvr it will // use the updated name for display purposes. this is only needed if // the registration process needs to use a different name than the one // we captured from the external provider var partialClaims = partial_user.Claims.Where(x => x.Type != Constants.ClaimTypes.Name).ToList(); partialClaims.Add(nameClaim); await ctx.Environment.UpdatePartialLoginClaimsAsync(partialClaims); // find the URL to continue with the process to the issue the token to the RP var resumeUrl = await ctx.Environment.GetPartialLoginResumeUrlAsync(); return(Redirect(resumeUrl)); } return(View()); }
public async Task <ActionResult> Index(ExternalRegistrationModel model) { var ctx = Request.GetOwinContext(); var partial_login = await ctx.Environment.GetIdentityServerPartialLoginAsync(); if (partial_login == null) { return(View("Error")); } if (ModelState.IsValid) { // update the "database" for our users with the registration data var nameIdClaim = partial_login.Claims.First(x => x.Type == Constants.ClaimTypes.ExternalProviderUserId); var provider = nameIdClaim.Issuer; var providerUserId = nameIdClaim.Value; var user = new SampleApp.RegisterFirstExternalRegistrationUserService.CustomUser { Subject = Guid.NewGuid().ToString(), Provider = provider, ProviderID = providerUserId, Claims = new List <Claim> { new Claim(Constants.ClaimTypes.Name, model.First + " " + model.Last), new Claim(Constants.ClaimTypes.GivenName, model.First), new Claim(Constants.ClaimTypes.FamilyName, model.Last), } }; SampleApp.RegisterFirstExternalRegistrationUserService.Users.Add(user); // find the URL to continue with the process to the issue the token to the RP var resumeUrl = await ctx.Environment.GetPartialLoginResumeUrlAsync(); return(Redirect(resumeUrl)); } return(View()); }