-
Notifications
You must be signed in to change notification settings - Fork 155
Unable to acquire token #240
Copy link
Copy link
Closed
Labels
EnhancementA request or suggestion to improve some aspect of the libraryA request or suggestion to improve some aspect of the libraryQuestionAny questions about how MSAL Java worksAny questions about how MSAL Java works
Description
Hi,
The following snippet of code was working fine and generating an access token couple of days back -
private static IAuthenticationResult acquireToken() throws Exception {
// Load token cache from file and initialize token cache aspect. The token cache will have
// dummy data, so the acquireTokenSilently call will fail.
TokenCacheAspect tokenCacheAspect = new TokenCacheAspect("sample_cache.json");
IClientCredential credential = ClientCredentialFactory.createFromSecret(CLIENT_SECRET);
ConfidentialClientApplication cca =
ConfidentialClientApplication
.builder(CLIENT_ID, credential)
.authority(AUTHORITY)
.setTokenCacheAccessAspect(tokenCacheAspect)
.build();
IAuthenticationResult result;
try {
SilentParameters silentParameters =
SilentParameters
.builder(SCOPE)
.build();
// try to acquire token silently. This call will fail since the token cache does not
// have a token for the application you are requesting an access token for
result = cca.acquireTokenSilently(silentParameters).join();
} catch (Exception ex) {
if (ex.getCause() instanceof MsalException) {
ClientCredentialParameters parameters =
ClientCredentialParameters
.builder(SCOPE)
.build();
// Try to acquire a token. If successful, you should see
// the token information printed out to console
result = cca.acquireToken(parameters).join();
} else {
// Handle other exceptions accordingly
throw ex;
}
}
return result;
}but today this exception is throw
java.util.concurrent.CompletionException: java.lang.NoSuchMethodError: net.minidev.json.JSONObject.getAsNumber(Ljava/lang/String;)Ljava/lang/Number;
Current setup -
- Apache Maven 3.6.3
- Java 1.8.0_252
- Spring Boot 2.3.0.RELEASE
- msal4j 1.5.0
Was using ms-graph-sdk 1.7.1 and ms-graph-core 1.0.1 but got same error even after removing them.
Pulling my hair out trying to figure out root cause. Not sure which dependency is causing this error. I see that msal4j uses net.minidev's json-smart 1.3.1

but excluding that dependency and using newer 2.3 version also did not help.
I have stripped my pom.xml to bare minimum but still no luck -
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>${ms-azure-msal4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
</dependencies>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
EnhancementA request or suggestion to improve some aspect of the libraryA request or suggestion to improve some aspect of the libraryQuestionAny questions about how MSAL Java worksAny questions about how MSAL Java works
Type
Projects
Status
Done (in PR or next release)