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
atEven 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
1 Related questions 0 Access token cannot be refreshed. Please re-authenticate 8 Java AES-128 encryption of 1 block (16 byte) returns 2 blocks(32 byte) as output 0 Class java.util.ArrayList has generic type parameters, use GenericTypeIndicator instead Related questions 0 Access token cannot be refreshed. Please re-authenticate 8 Java AES-128 encryption of 1 block (16 byte) returns 2 blocks(32 byte) as output 0 Class java.util.ArrayList has generic type parameters, use GenericTypeIndicator instead 5 Getting error 504, Gateway Timeout, while fetching messages from the MS Graph API 1 Microsoft Graph API "Access is denied" while trying to read the ItemAttachment Properties with $expand() 0 Using userPrincipalName of a user created in tenant while sending mails using Graph API 1 Get 405/404 error when trying to send mails with Graph API (OAuth2 client credentials flow) 1 Microsoft graph API: getting 403 while trying to read user groups 8 Type mismatch in key from map: expected .. Text, received ... LongWritable Load 6 more related questions Show fewer related questions Reset to default