0
votes

I am having an application which fetches access token from Microsoft Graph and then uses the access token to make calls to Microsoft Graph Apis.

I am using Client Certificate authentication using MSAL jar. Now I am not sure if the method is using SSL to fetch access token(Since I am directly reading the .pfx certificate as file input stream).

Below is my code:

public String getTokenUsingGraphCertificate(String clientId, String tenantId, String certificatePath, String certificatePassword) throws Exception {
        
        String authority = MessageFormat.format(AUTHORITY_URL, tenantId);
        IClientCredential credential = ClientCredentialFactory.createFromCertificate(
                new FileInputStream(new File(certificatePath)), certificatePassword);
        ConfidentialClientApplication cca = ConfidentialClientApplication.builder(clientId, credential)
                .authority(authority)
                // .setTokenCacheAccessAspect(tokenCacheAspect)
                .build();

        IAuthenticationResult result;
        try {
            SilentParameters silentParameters = SilentParameters.builder(SCOPE).build();
            result = cca.acquireTokenSilently(silentParameters).join();
        } catch (Exception ex) {
            if (ex.getCause() instanceof MsalException) {

                ClientCredentialParameters parameters = ClientCredentialParameters.builder(SCOPE).build();
                result = cca.acquireToken(parameters).join();
            } else {
                log.error("Exception occurred while fetching access token using getTokenUsingGraphCertificate. ERROR is : {}",ex);
                throw ex;
            }
        }
        return result.accessToken();
    }

Now, How could I use SSL to fetch access token from Microsoft Graph using Client Certificate? Please help. Thanks in advance

1

1 Answers

0
votes

MSAL uses SSL to get the tokens from the auth endpoint. You can verify this with a tool like Fiddler to watch the traffic.