public interface IBroker
Authentication brokers provide a centralized way to handle authentication across multiple applications on a device or platform. They can offer benefits such as single sign-on (SSO) between applications, consistent authentication experiences, and leveraging platform security features.
All methods are marked as default so they can be referenced by MSAL Java without an implementation, and most will simply throw an exception if not overridden by an IBroker implementation.
| Modifier and Type | Method and Description |
|---|---|
default CompletableFuture<IAuthenticationResult> |
acquireToken(PublicClientApplication application,
InteractiveRequestParameters parameters)
Acquires a token interactively by prompting the user to enter credentials.
|
default CompletableFuture<IAuthenticationResult> |
acquireToken(PublicClientApplication application,
SilentParameters requestParameters)
Acquires a token silently without user interaction.
|
default CompletableFuture<IAuthenticationResult> |
acquireToken(PublicClientApplication application,
UserNamePasswordParameters parameters)
Acquires a token silently using username and password authentication.
|
default boolean |
isBrokerAvailable()
Checks whether a broker is available and ready to use on this machine.
|
default IAuthenticationResult |
parseBrokerAuthResult(String authority,
String idToken,
String accessToken,
String accountId,
String clientInfo,
long accessTokenExpirationTime,
boolean isPopAuthorization)
MSAL Java's AuthenticationResult requires several package-private classes that a broker implementation can't access,
so this helper method can be used to create AuthenticationResults from within the MSAL Java package
|
default void |
removeAccount(PublicClientApplication application,
IAccount account)
Removes an account from the broker's token cache.
|
default CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, SilentParameters requestParameters)
This may be accomplished by returning tokens from a token cache, using cached refresh tokens to get new tokens, or via any authentication flow where a user is not prompted to enter credentials.
application - The public client application requesting the tokenrequestParameters - Parameters for the silent token requestMsalClientException - If no broker implementation is availabledefault CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, InteractiveRequestParameters parameters)
This method presents a user interface requesting credentials from the user and handles the interactive authentication flow.
application - The public client application requesting the tokenparameters - Parameters for the interactive token requestMsalClientException - If no broker implementation is availabledefault CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, UserNamePasswordParameters parameters)
This method enables resource owner password credentials (ROPC) flow through a broker. Note that this flow is not recommended for production applications as it requires handling user credentials directly.
application - The public client application requesting the tokenparameters - Parameters containing username, password and other request detailsMsalClientException - If no broker implementation is availabledefault void removeAccount(PublicClientApplication application, IAccount account) throws MsalClientException
This method allows applications to sign out users and remove their tokens from the broker cache.
application - The public client application requesting the account removalaccount - The account to be removed from the token cacheMsalClientException - If no broker implementation is availabledefault boolean isBrokerAvailable()
Applications should call this method before attempting to use broker-specific features to determine if a broker is installed and accessible.
MsalClientException - If no broker implementation is availabledefault IAuthenticationResult parseBrokerAuthResult(String authority, String idToken, String accessToken, String accountId, String clientInfo, long accessTokenExpirationTime, boolean isPopAuthorization)
Copyright © 2013–2025. All rights reserved.