diff --git a/NuGet.config b/NuGet.config index d740919f9061..d263ff7579a8 100644 --- a/NuGet.config +++ b/NuGet.config @@ -6,19 +6,10 @@ - - - - - - - - - + - - + @@ -39,19 +30,10 @@ - - - - - - - - - + - - + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 45754ff12840..3744a021b8c8 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -9,37 +9,37 @@ --> - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 - + https://dev.azure.com/dnceng/internal/_git/dotnet-efcore - 1bdfaaeddf567214d363aa2396fd4874abf204cc + d00955545e8afc997726aead9b0e6103b1ceade6 https://dev.azure.com/dnceng/internal/_git/dotnet-runtime @@ -121,9 +121,9 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-runtime 5535e31a712343a63f5d7d796cd874e563e5ac14 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 https://dev.azure.com/dnceng/internal/_git/dotnet-runtime @@ -139,7 +139,7 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 https://dev.azure.com/dnceng/internal/_git/dotnet-runtime @@ -185,9 +185,9 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-runtime 5535e31a712343a63f5d7d796cd874e563e5ac14 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 https://github.com/dotnet/source-build-externals @@ -275,17 +275,17 @@ https://dev.azure.com/dnceng/internal/_git/dotnet-runtime 81cabf2857a01351e5ab578947c7403a5b128ad1 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 https://dev.azure.com/dnceng/internal/_git/dotnet-runtime @@ -316,22 +316,22 @@ Win-x64 is used here because we have picked an arbitrary runtime identifier to flow the version of the latest NETCore.App runtime. All Runtime.$rid packages should have the same version. --> - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 https://github.com/dotnet/xdt @@ -368,9 +368,9 @@ - + https://dev.azure.com/dnceng/internal/_git/dotnet-runtime - eba546b0f0d448e0176a2222548fd7a2fbf464c0 + 1584e493603cfc4e9b36b77d6d4afe97de6363f9 https://github.com/dotnet/winforms diff --git a/eng/Versions.props b/eng/Versions.props index ddc585f98ec2..de7ba7844e19 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -67,12 +67,12 @@ 8.0.2 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13-servicing.25066.9 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14-servicing.25111.18 8.0.0 8.0.1 8.0.0 @@ -93,7 +93,7 @@ 8.0.0 8.0.0 8.0.0 - 8.0.13-servicing.25066.9 + 8.0.14-servicing.25111.18 8.0.1 8.0.1 8.0.1 @@ -109,7 +109,7 @@ 8.0.0 8.0.2 8.0.0 - 8.0.13-servicing.25066.9 + 8.0.14-servicing.25111.18 8.0.1 8.0.1 8.0.1 @@ -129,9 +129,9 @@ 8.0.0 8.0.0 8.0.0 - 8.0.13-servicing.25066.9 + 8.0.14-servicing.25111.18 - 8.0.13-servicing.25066.9 + 8.0.14-servicing.25111.18 8.0.0 8.0.1 @@ -143,14 +143,14 @@ 8.1.0-preview.23604.1 8.1.0-preview.23604.1 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 - 8.0.13 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 + 8.0.14 4.8.0-7.24574.2 4.8.0-7.24574.2 diff --git a/src/Identity/Core/src/SignInManager.cs b/src/Identity/Core/src/SignInManager.cs index b5659b329854..66f06c4d3465 100644 --- a/src/Identity/Core/src/SignInManager.cs +++ b/src/Identity/Core/src/SignInManager.cs @@ -162,8 +162,21 @@ public virtual async Task CanSignInAsync(TUser user) public virtual async Task RefreshSignInAsync(TUser user) { var auth = await Context.AuthenticateAsync(AuthenticationScheme); - IList claims = Array.Empty(); + if (!auth.Succeeded || auth.Principal?.Identity?.IsAuthenticated != true) + { + Logger.LogError("RefreshSignInAsync prevented because the user is not currently authenticated. Use SignInAsync instead for initial sign in."); + return; + } + var authenticatedUserId = UserManager.GetUserId(auth.Principal); + var newUserId = await UserManager.GetUserIdAsync(user); + if (authenticatedUserId == null || authenticatedUserId != newUserId) + { + Logger.LogError("RefreshSignInAsync prevented because currently authenticated user has a different UserId. Use SignInAsync instead to change users."); + return; + } + + IList claims = Array.Empty(); var authenticationMethod = auth?.Principal?.FindFirst(ClaimTypes.AuthenticationMethod); var amr = auth?.Principal?.FindFirst("amr"); diff --git a/src/Identity/test/Identity.Test/SignInManagerTest.cs b/src/Identity/test/Identity.Test/SignInManagerTest.cs index d1072676138a..73fe6d6be218 100644 --- a/src/Identity/test/Identity.Test/SignInManagerTest.cs +++ b/src/Identity/test/Identity.Test/SignInManagerTest.cs @@ -592,38 +592,38 @@ public async Task CanExternalSignIn(bool isPersistent, bool supportsLockout) [InlineData(true, false)] [InlineData(false, true)] [InlineData(false, false)] - public async Task CanResignIn( - // Suppress warning that says theory methods should use all of their parameters. - // See comments below about why this isn't used. -#pragma warning disable xUnit1026 - bool isPersistent, -#pragma warning restore xUnit1026 - bool externalLogin) + public async Task CanResignIn(bool isPersistent, bool externalLogin) { // Setup var user = new PocoUser { UserName = "Foo" }; var context = new DefaultHttpContext(); var auth = MockAuth(context); var loginProvider = "loginprovider"; - var id = new ClaimsIdentity(); + var id = new ClaimsIdentity("authscheme"); if (externalLogin) { id.AddClaim(new Claim(ClaimTypes.AuthenticationMethod, loginProvider)); } - // REVIEW: auth changes we lost the ability to mock is persistent - //var properties = new AuthenticationProperties { IsPersistent = isPersistent }; - var authResult = AuthenticateResult.NoResult(); + + var claimsPrincipal = new ClaimsPrincipal(id); + var properties = new AuthenticationProperties { IsPersistent = isPersistent }; + var authResult = AuthenticateResult.Success(new AuthenticationTicket(claimsPrincipal, properties, "authscheme")); auth.Setup(a => a.AuthenticateAsync(context, IdentityConstants.ApplicationScheme)) .Returns(Task.FromResult(authResult)).Verifiable(); var manager = SetupUserManager(user); + manager.Setup(m => m.GetUserId(claimsPrincipal)).Returns(user.Id.ToString()); var signInManager = new Mock>(manager.Object, new HttpContextAccessor { HttpContext = context }, new Mock>().Object, null, null, new Mock().Object, null) { CallBase = true }; - //signInManager.Setup(s => s.SignInAsync(user, It.Is(p => p.IsPersistent == isPersistent), - //externalLogin? loginProvider : null)).Returns(Task.FromResult(0)).Verifiable(); - signInManager.Setup(s => s.SignInWithClaimsAsync(user, It.IsAny(), It.IsAny>())).Returns(Task.FromResult(0)).Verifiable(); + + signInManager.Setup(s => s.SignInWithClaimsAsync(user, + It.Is(properties => properties.IsPersistent == isPersistent), + It.Is>(claims => !externalLogin || + claims.Any(claim => claim.Type == ClaimTypes.AuthenticationMethod && claim.Value == loginProvider)))) + .Returns(Task.FromResult(0)).Verifiable(); + signInManager.Object.Context = context; // Act @@ -634,6 +634,58 @@ public async Task CanResignIn( signInManager.Verify(); } + [Fact] + public async Task ResignInNoOpsAndLogsErrorIfNotAuthenticated() + { + var user = new PocoUser { UserName = "Foo" }; + var context = new DefaultHttpContext(); + var auth = MockAuth(context); + var manager = SetupUserManager(user); + var logger = new TestLogger>(); + var signInManager = new Mock>(manager.Object, + new HttpContextAccessor { HttpContext = context }, + new Mock>().Object, + null, logger, new Mock().Object, null) + { CallBase = true }; + auth.Setup(a => a.AuthenticateAsync(context, IdentityConstants.ApplicationScheme)) + .Returns(Task.FromResult(AuthenticateResult.NoResult())).Verifiable(); + + await signInManager.Object.RefreshSignInAsync(user); + + Assert.Contains("RefreshSignInAsync prevented because the user is not currently authenticated. Use SignInAsync instead for initial sign in.", logger.LogMessages); + auth.Verify(); + signInManager.Verify(s => s.SignInWithClaimsAsync(It.IsAny(), It.IsAny(), It.IsAny>()), + Times.Never()); + } + + [Fact] + public async Task ResignInNoOpsAndLogsErrorIfAuthenticatedWithDifferentUser() + { + var user = new PocoUser { UserName = "Foo" }; + var context = new DefaultHttpContext(); + var auth = MockAuth(context); + var manager = SetupUserManager(user); + var logger = new TestLogger>(); + var signInManager = new Mock>(manager.Object, + new HttpContextAccessor { HttpContext = context }, + new Mock>().Object, + null, logger, new Mock().Object, null) + { CallBase = true }; + var id = new ClaimsIdentity("authscheme"); + var claimsPrincipal = new ClaimsPrincipal(id); + var authResult = AuthenticateResult.Success(new AuthenticationTicket(claimsPrincipal, new AuthenticationProperties(), "authscheme")); + auth.Setup(a => a.AuthenticateAsync(context, IdentityConstants.ApplicationScheme)) + .Returns(Task.FromResult(authResult)).Verifiable(); + manager.Setup(m => m.GetUserId(claimsPrincipal)).Returns("different"); + + await signInManager.Object.RefreshSignInAsync(user); + + Assert.Contains("RefreshSignInAsync prevented because currently authenticated user has a different UserId. Use SignInAsync instead to change users.", logger.LogMessages); + auth.Verify(); + signInManager.Verify(s => s.SignInWithClaimsAsync(It.IsAny(), It.IsAny(), It.IsAny>()), + Times.Never()); + } + [Theory] [InlineData(true, true, true, true)] [InlineData(true, true, false, true)]