Skip to content

Commit a662ad5

Browse files
committed
Re-add exception throw when B2C is used with device code flow
1 parent 06fe229 commit a662ad5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/java/com/microsoft/aad/msal4j/PublicClientApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public CompletableFuture<IAuthenticationResult> acquireToken(IntegratedWindowsAu
5555
@Override
5656
public CompletableFuture<IAuthenticationResult> acquireToken(DeviceCodeFlowParameters parameters) {
5757

58+
if (!(AuthorityType.AAD.equals(authenticationAuthority.authorityType()) ||
59+
AuthorityType.ADFS.equals(authenticationAuthority.authorityType()))) {
60+
throw new IllegalArgumentException(
61+
"Invalid authority type. Device Flow is only supported by AAD and ADFS authority");
62+
}
63+
5864
validateNotNull("parameters", parameters);
5965

6066
AtomicReference<CompletableFuture<IAuthenticationResult>> futureReference =

src/test/java/com/microsoft/aad/msal4j/DeviceCodeFlowTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ public void deviceCodeFlowTest() throws Exception {
149149
PowerMock.verify();
150150
}
151151

152+
@Test(expectedExceptions = IllegalArgumentException.class,
153+
expectedExceptionsMessageRegExp = "Invalid authority type. Device Flow is only supported by AAD and ADFS authority")
154+
public void executeAcquireDeviceCode_B2CAuthorityUsed_IllegalArgumentExceptionThrown()
155+
throws Exception {
156+
157+
app = PublicClientApplication.builder("client_id")
158+
.b2cAuthority(TestConfiguration.B2C_AUTHORITY)
159+
.validateAuthority(false).build();
160+
161+
app.acquireToken
162+
(DeviceCodeFlowParameters
163+
.builder(Collections.singleton(AAD_RESOURCE_ID), (DeviceCode deviceCode) -> {})
164+
.build());
165+
}
166+
152167
@Test
153168
public void executeAcquireDeviceCode_AuthenticaionPendingErrorReturned_AuthenticationExceptionThrown()
154169
throws Exception {

0 commit comments

Comments
 (0)