Skip to content

Commit

Permalink
Fix for #4652
Browse files Browse the repository at this point in the history
  • Loading branch information
bgavrilMS committed Mar 20, 2024
1 parent cea9ed7 commit 40074f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ internal abstract class RequestBase
throw new ArgumentNullException(nameof(acquireTokenParameters));
}

ValidateScopeInput(authenticationRequestParameters.Scope);
acquireTokenParameters.LogParameters(AuthenticationRequestParameters.RequestContext.Logger);
}

Expand All @@ -63,15 +62,7 @@ internal abstract class RequestBase
protected virtual SortedSet<string> GetOverriddenScopes(ISet<string> inputScopes)
{
return null;
}

private void ValidateScopeInput(ISet<string> scopesToValidate)
{
if (scopesToValidate.Contains(AuthenticationRequestParameters.AppConfig.ClientId))
{
throw new ArgumentException("API does not accept client id as a user-provided scope");
}
}
}

protected abstract Task<AuthenticationResult> ExecuteAsync(CancellationToken cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -275,6 +275,37 @@ public async Task B2C_NoScopes_NoAccessToken_Async()
}
}

/// <summary>
/// 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.
/// </summary>
[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()
{
Expand Down

0 comments on commit 40074f0

Please sign in to comment.