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

@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.Identity.UI.V3.Pages.Account.Internal
return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }); return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email });
} }
await _signInManager.SignInAsync(user, isPersistent: false); await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider);
return LocalRedirect(returnUrl); 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 }); return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email });
} }
await _signInManager.SignInAsync(user, isPersistent: false); await _signInManager.SignInAsync(user, isPersistent: false, info.LoginProvider);
return LocalRedirect(returnUrl); 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
using Identity.DefaultUI.WebSite; using Identity.DefaultUI.WebSite;
using Microsoft.AspNetCore.Identity.UI.Services; using Microsoft.AspNetCore.Identity.UI.Services;
@ -218,5 +219,31 @@ namespace Microsoft.AspNetCore.Identity.FunctionalTests
// Act & Assert // Act & Assert
await UserStories.RegisterNewUserWithSocialLoginAsync(client, userName, email); 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);
}
} }
} }