diff --git a/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/ExternalLogin.cshtml.cs b/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/ExternalLogin.cshtml.cs index 549e6029cb..dbf5c24f64 100644 --- a/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/ExternalLogin.cshtml.cs +++ b/src/Identity/UI/src/Areas/Identity/Pages/V3/Account/ExternalLogin.cshtml.cs @@ -208,14 +208,14 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by clicking here."); - + // If account confirmation is required, we need to show the link if we don't have a real email sender if (_userManager.Options.SignIn.RequireConfirmedAccount) { return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }); } - await _signInManager.SignInAsync(user, isPersistent: false); + await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider); return LocalRedirect(returnUrl); } diff --git a/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/ExternalLogin.cshtml.cs b/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/ExternalLogin.cshtml.cs index 62df7a64f4..5b580b865c 100644 --- a/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/ExternalLogin.cshtml.cs +++ b/src/Identity/UI/src/Areas/Identity/Pages/V4/Account/ExternalLogin.cshtml.cs @@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }); } - await _signInManager.SignInAsync(user, isPersistent: false); + await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider); return LocalRedirect(returnUrl); } } diff --git a/src/Identity/test/Identity.FunctionalTests/RegistrationTests.cs b/src/Identity/test/Identity.FunctionalTests/RegistrationTests.cs index a07404d666..55d3cb693f 100644 --- a/src/Identity/test/Identity.FunctionalTests/RegistrationTests.cs +++ b/src/Identity/test/Identity.FunctionalTests/RegistrationTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Security.Claims; using System.Threading.Tasks; using Identity.DefaultUI.WebSite; using Microsoft.AspNetCore.Identity.UI.Services; @@ -175,7 +176,7 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests // Act & Assert await UserStories.RegisterNewUserWithSocialLoginWithConfirmationAsync(client, userName, email, hasRealEmailSender: true); - Assert.Single(emailSender.SentEmails); + Assert.Single(emailSender.SentEmails); } [Fact] @@ -218,5 +219,31 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests // Act & Assert await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email); } + + [Fact] + public async Task RegisterWithASocialLoginProviderSetsAuthenticationMethodClaim() + { + // Arrange + string authenticationMethod = null; + + void ConfigureTestServices(IServiceCollection services) => + services + .SetupTestThirdPartyLogin() + .SetupGetUserClaimsPrincipal(user => + authenticationMethod = user.FindFirstValue(ClaimTypes.AuthenticationMethod), IdentityConstants.ApplicationScheme); + + var client = ServerFactory + .WithWebHostBuilder(whb => whb.ConfigureServices(ConfigureTestServices)) + .CreateClient(); + + var guid = Guid.NewGuid(); + var userName = $"{guid}"; + var email = $"{guid}@example.com"; + + // Act & Assert + await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email); + + Assert.Equal("Contoso", authenticationMethod); + } } }