diff --git a/src/Identity/Core/ref/Microsoft.AspNetCore.Identity.netcoreapp3.0.cs b/src/Identity/Core/ref/Microsoft.AspNetCore.Identity.netcoreapp3.0.cs index 12a6baf67a..a57c5891f1 100644 --- a/src/Identity/Core/ref/Microsoft.AspNetCore.Identity.netcoreapp3.0.cs +++ b/src/Identity/Core/ref/Microsoft.AspNetCore.Identity.netcoreapp3.0.cs @@ -35,6 +35,7 @@ namespace Microsoft.AspNetCore.Identity public partial class ExternalLoginInfo : Microsoft.AspNetCore.Identity.UserLoginInfo { public ExternalLoginInfo(System.Security.Claims.ClaimsPrincipal principal, string loginProvider, string providerKey, string displayName) : base (default(string), default(string), default(string)) { } + public Microsoft.AspNetCore.Authentication.AuthenticationProperties AuthenticationProperties { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public System.Collections.Generic.IEnumerable AuthenticationTokens { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } public System.Security.Claims.ClaimsPrincipal Principal { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } } diff --git a/src/Identity/Core/src/ExternalLoginInfo.cs b/src/Identity/Core/src/ExternalLoginInfo.cs index 5fcca2c6a7..255a00de67 100644 --- a/src/Identity/Core/src/ExternalLoginInfo.cs +++ b/src/Identity/Core/src/ExternalLoginInfo.cs @@ -35,5 +35,10 @@ namespace Microsoft.AspNetCore.Identity /// The s associated with this login. /// public IEnumerable AuthenticationTokens { get; set; } + + /// + /// The associated with this login. + /// + public AuthenticationProperties AuthenticationProperties { get; set; } } } diff --git a/src/Identity/Core/src/SignInManager.cs b/src/Identity/Core/src/SignInManager.cs index 3435099abc..8cae14795a 100644 --- a/src/Identity/Core/src/SignInManager.cs +++ b/src/Identity/Core/src/SignInManager.cs @@ -668,7 +668,8 @@ namespace Microsoft.AspNetCore.Identity ?? provider; return new ExternalLoginInfo(auth.Principal, provider, providerKey, providerDisplayName) { - AuthenticationTokens = auth.Properties.GetTokens() + AuthenticationTokens = auth.Properties.GetTokens(), + AuthenticationProperties = auth.Properties }; } diff --git a/src/Identity/test/Identity.Test/SignInManagerTest.cs b/src/Identity/test/Identity.Test/SignInManagerTest.cs index 40507099e0..2135608e81 100644 --- a/src/Identity/test/Identity.Test/SignInManagerTest.cs +++ b/src/Identity/test/Identity.Test/SignInManagerTest.cs @@ -979,5 +979,40 @@ namespace Microsoft.AspNetCore.Identity.Test // Assert Assert.Equal("Blah blah", externalLoginInfo.ProviderDisplayName); } + + [Fact] + public async Task ExternalLoginInfoAsyncReturnsAuthenticationPropertiesWithCustomValue() + { + // Arrange + var user = new PocoUser { Id = "foo", UserName = "Foo" }; + var userManager = SetupUserManager(user); + var context = new DefaultHttpContext(); + var identity = new ClaimsIdentity(); + identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "bar")); + var principal = new ClaimsPrincipal(identity); + var properties = new AuthenticationProperties(); + properties.Items["LoginProvider"] = "blah"; + properties.Items["CustomValue"] = "fizzbuzz"; + var authResult = AuthenticateResult.Success(new AuthenticationTicket(principal, properties, "blah")); + var auth = MockAuth(context); + auth.Setup(s => s.AuthenticateAsync(context, IdentityConstants.ExternalScheme)).ReturnsAsync(authResult); + var schemeProvider = new Mock(); + var handler = new Mock(); + schemeProvider.Setup(s => s.GetAllSchemesAsync()) + .ReturnsAsync(new[] + { + new AuthenticationScheme("blah", "Blah blah", handler.Object.GetType()) + }); + var signInManager = SetupSignInManager(userManager.Object, context, schemeProvider: schemeProvider.Object); + var externalLoginInfo = await signInManager.GetExternalLoginInfoAsync(); + + // Act + var externalProperties = externalLoginInfo.AuthenticationProperties; + var customValue = externalProperties?.Items["CustomValue"]; + + // Assert + Assert.NotNull(externalProperties); + Assert.Equal("fizzbuzz", customValue); + } } }