* Fixes #11405 - Adds AuthenticationProperties to ExternalLoginInfo in SignInManager.GetExternalLoginInfoAsync(). * Public API changed; ran dotnet msbuild /t:GenerateReferenceSource in src/Identity/Core/src per docs/ReferenceAssemblies.md. * Add unit test to verify SignInManager.GetExternalLoginInfoAsync() can return CustomValue from ExternalLoginInfo.AuthenticationProperties.Items.
This commit is contained in:
parent
5458a102e6
commit
32782cb421
|
|
@ -35,6 +35,7 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
public partial class ExternalLoginInfo : Microsoft.AspNetCore.Identity.UserLoginInfo
|
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 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<Microsoft.AspNetCore.Authentication.AuthenticationToken> AuthenticationTokens { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Authentication.AuthenticationToken> 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 { } }
|
public System.Security.Claims.ClaimsPrincipal Principal { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,5 +35,10 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
/// The <see cref="AuthenticationToken"/>s associated with this login.
|
/// The <see cref="AuthenticationToken"/>s associated with this login.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<AuthenticationToken> AuthenticationTokens { get; set; }
|
public IEnumerable<AuthenticationToken> AuthenticationTokens { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="Authentication.AuthenticationProperties"/> associated with this login.
|
||||||
|
/// </summary>
|
||||||
|
public AuthenticationProperties AuthenticationProperties { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -668,7 +668,8 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
?? provider;
|
?? provider;
|
||||||
return new ExternalLoginInfo(auth.Principal, provider, providerKey, providerDisplayName)
|
return new ExternalLoginInfo(auth.Principal, provider, providerKey, providerDisplayName)
|
||||||
{
|
{
|
||||||
AuthenticationTokens = auth.Properties.GetTokens()
|
AuthenticationTokens = auth.Properties.GetTokens(),
|
||||||
|
AuthenticationProperties = auth.Properties
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -979,5 +979,40 @@ namespace Microsoft.AspNetCore.Identity.Test
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal("Blah blah", externalLoginInfo.ProviderDisplayName);
|
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<IAuthenticationSchemeProvider>();
|
||||||
|
var handler = new Mock<IAuthenticationHandler>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue