Set AuthenticationMethod for first Identity external login (#18296)
This commit is contained in:
parent
c5dd4ce7e3
commit
ccf3c4e6b8
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue