From 9b4ab47e838312e10ae344d627e85102e67be25f Mon Sep 17 00:00:00 2001 From: Bogdan Gavril Date: Tue, 12 Mar 2024 14:12:46 +0000 Subject: [PATCH] Fix for #4652 --- .../Internal/Requests/RequestBase.cs | 11 +------ .../PublicClientApplicationTestsWithB2C.cs | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/client/Microsoft.Identity.Client/Internal/Requests/RequestBase.cs b/src/client/Microsoft.Identity.Client/Internal/Requests/RequestBase.cs index 8d61c6b4ef..babdd500ed 100644 --- a/src/client/Microsoft.Identity.Client/Internal/Requests/RequestBase.cs +++ b/src/client/Microsoft.Identity.Client/Internal/Requests/RequestBase.cs @@ -51,7 +51,6 @@ protected RequestBase( throw new ArgumentNullException(nameof(acquireTokenParameters)); } - ValidateScopeInput(authenticationRequestParameters.Scope); acquireTokenParameters.LogParameters(AuthenticationRequestParameters.RequestContext.Logger); } @@ -63,15 +62,7 @@ protected RequestBase( protected virtual SortedSet GetOverriddenScopes(ISet inputScopes) { return null; - } - - private void ValidateScopeInput(ISet scopesToValidate) - { - if (scopesToValidate.Contains(AuthenticationRequestParameters.AppConfig.ClientId)) - { - throw new ArgumentException("API does not accept client id as a user-provided scope"); - } - } + } protected abstract Task ExecuteAsync(CancellationToken cancellationToken); diff --git a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/PublicClientApplicationTestsWithB2C.cs b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/PublicClientApplicationTestsWithB2C.cs index c11d0c2384..9f363862bd 100644 --- a/tests/Microsoft.Identity.Test.Unit/PublicApiTests/PublicClientApplicationTestsWithB2C.cs +++ b/tests/Microsoft.Identity.Test.Unit/PublicApiTests/PublicClientApplicationTestsWithB2C.cs @@ -17,7 +17,7 @@ namespace Microsoft.Identity.Test.Unit.PublicApiTests { [TestClass] [TestCategory(TestCategories.B2C)] - public class PublicClientApplicationTestsWithB2C : TestBase + public class B2C_E2E_Tests : TestBase { [TestInitialize] public override void TestInitialize() @@ -275,6 +275,37 @@ public async Task B2C_NoScopes_NoAccessToken_Async() } } + /// + /// If no scopes are passed in, B2C does not return a AT. MSAL must be able to + /// persist the data to the cache and return an AuthenticationResult. + /// This behavior has been seen on B2C, as AAD will return an access token for the implicit scopes. + /// + [TestMethod] + public async Task B2C_ClientId_Async() + { + + using (var httpManager = new MockHttpManager()) + { + ConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(TestConstants.ClientId) + .WithAuthority(new Uri(TestConstants.B2CLoginAuthority), true) + .WithClientSecret(TestConstants.ClientSecret) + .WithHttpManager(httpManager) + .BuildConcrete(); + + httpManager.AddSuccessTokenResponseMockHandlerForPost(TestConstants.B2CLoginAuthority); + + // Act + AuthenticationResult result = await app + .AcquireTokenByAuthorizationCode(new[] { TestConstants.ClientId }, "code" ) + .ExecuteAsync() + .ConfigureAwait(false); + + // Assert + Assert.IsNotNull(result.AccessToken); + + } + } + [TestMethod] public async Task B2CSomeExceptionAsync() {