Set AuthenticationMethod for first Identity external login (#18296)

This commit is contained in:
Kirk Larkin 2020-02-12 21:20:31 +00:00 committed by GitHub
parent c5dd4ce7e3
commit ccf3c4e6b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 4 deletions

View File

@ -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 <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
// 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);
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}