In OAuth client credentials flow using Java, is the use of SilentParameters to acquire token silently from cache obsolete?

Priyanka Chaudhuri 125 Reputation points
2023-07-11T15:33:42.0033333+00:00

My client application is a confidential client application as it does not have any interactive UI for user sign in (no user sign in involved) and it runs on the web browser.

In SDK for Java quickstart as well as many online implementations of Client Credentials Grant flow in Java for a daemon calling a protected web API using app role, SilentParameters.builder(Set<String>scope) has been used as an example.

Right now it is deprecated in the MSAL (I am using 1.13.8 maven dependency) and I want to understand the following -

Should I only use the below code to acquire token and I no longer need to use SilentParameters and call "acquireTokenSilently"? Is it that the ClientCredentialParameters will implicitly check for a valid token in the cache and if not found, would request a new token to the IDP?

Articles like https://learn.microsoft.com/en-us/answers/questions/61061/recommended-pattern-for-acquiring-tokens and https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-acquire-cache-tokens#recommended-call-pattern-for-public-client-applications has left me rather confused.

ClientCredentialParameters parameters =
                     ClientCredentialParameters
                             .builder(SCOPE)
                             .build();
result = cca.acquireToken(parameters).join();
Microsoft Security Microsoft Entra Microsoft Entra ID
Microsoft Security Microsoft Identity Manager
{count} votes

Accepted answer
  1. Akshay-MSFT 17,951 Reputation points Microsoft Employee Moderator
    2023-07-12T13:32:14.1833333+00:00

    @Priyanka Chaudhuri

    Thank you for posting your query on Microsoft Q&A. From above description we could understand that you want to know if you could use SilentParameters to acquireToken silently for java confidential client application.

    Please do correct me if this is not the case by responding in the comments section.

    Yes, you could use SilentParameters to acquireToken silently. As per Acquiring tokens silently MSAL maintains a token cache (or two caches for confidential client applications) and caches a token after it's been acquired.

    The exception applies to public clients only.

    For public client Client credentials flow, which does not use the user token cache but an application token cache. This method takes care of verifying the application token cache before sending a request to the security token service (STS).

    Please do let me know if you have any further queries.

    Thanks,

    Akshay Kaushik

    Please "Accept the answer" (Yes), and share your feedback if the suggestion answers you’re your query. This will help us and others in the community as well.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.