Getting the Error Java. Lang. Noclassdeffounderror: Com/Nimbusds/Oauth2/Sdk/Auth/Clientauthentication While Trying to Read the Mails from Graph Api
Import Com. Microsoft. Aad. Msal4J. Clientcredentialfactory; Import Com. Microsoft. Aad. Msal4J. Clientcredentialparameters; Import Com. Microsoft. Aad...
import com.microsoft.aad.msal4j.ClientCredentialFactory;
import com.microsoft.aad.msal4j.ClientCredentialParameters;
import com.microsoft.aad.msal4j.ConfidentialClientApplication;
import com.microsoft.aad.msal4j.IAuthenticationResult;
import com.microsoft.aad.msal4j.IClientCredential;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DefaultEmailReaderGraph implements CreationService {
DefaultEmailReaderGraph () {
}
public static final String CLIENT_ID = "800e0bd6-7848-4027-****-************";
private static final String AUTHORITY = "";
private static final String CLIENT_SECRET = "******ZNodD*****ShmFB2yG46zi************";
private static final String TENANT_GUID="7370fc8f-4ead-****-****-************";
private static final Set<String> SCOPES = Collections.singleton("");
private static final Logger LOG = LoggerFactory.getLogger(DefaultEmailReaderGraph.class);
private static IAuthenticationResult getAccessToken() throws Exception {
IAuthenticationResult result = null;
try{
IClientCredential credential = ClientCredentialFactory.createFromSecret(CLIENT_SECRET);
ConfidentialClientApplication app = ConfidentialClientApplication
.builder(CLIENT_ID, credential)
.authority(AUTHORITY)
.build();
ClientCredentialParameters clientCredentialParameter = ClientCredentialParameters
.builder(SCOPES)
.build();
CompletableFuture<IAuthenticationResult> future=app.acquireToken(clientCredentialParameter);
result=future.get();
final String accessToken=result.accessToken();
if(StringUtils.isBlank(accessToken)){
LOG.error("Access Token :"+accessToken);
}
LOG.info("Token is : "+app.acquireToken(clientCredentialParameter).join());
}catch (Exception e){
LOG.error("Exception in acquiring token: "+e.getMessage(),e);
}
return result;
}
@Override
public void createTicketFromEmail(Date lastEmailReadTime) throws Exception {
IAuthenticationResult accessToke= getAccessToken();
}
}
For the above code I am getting the below error in the console,
Caught throwable com/nimbusds/oauth2/sdk/auth/ClientAuthentication
java.lang.NoClassDefFoundError: com/nimbusds/oauth2/sdk/auth/ClientAuthentication
at
Even thought I have added the jar for the nimbusds (nimbus-jose-jwt-9.31.wso2v1) to the lib folder.
I am trying to generate the access token from the above code so I can further use it to read the email from the Azure AD Mailbox