private String acquireToken()

in mail-ms-exchange-oauth2/src/main/java/org/apache/camel/example/mail/oauth2/Oauth2ExchangeMailAuthenticator.java [54:81]


    private String acquireToken() {

        ConfidentialClientApplication cca;
        try {
            // This is the secret that is created in the Azure portal when registering the application
            IClientCredential credential = ClientCredentialFactory.createFromSecret(clientSecret);

            cca = ConfidentialClientApplication
                    .builder(clientId, credential)
                    .authority(authority)
                    .build();
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }

        // Client credential requests will by default try to look for a valid token in the
        // in-memory token cache. If found, it will return this token. If a token is not found, or the
        // token is not valid, it will fall back to acquiring a token from the AAD service. Although
        // not recommended unless there is a reason for doing so, you can skip the cache lookup
        // by using .skipCache(true) in ClientCredentialParameters.
        ClientCredentialParameters parameters =
                ClientCredentialParameters
                        .builder(SCOPE)
                        .build();

        IAuthenticationResult result = cca.acquireToken(parameters).join();
        return result.accessToken();
    }