SingleAccountPublicClientApplication Class

public class SingleAccountPublicClientApplication extends PublicClientApplication implements ISingleAccountPublicClientApplication

Field Summary

Modifier and Type Field and Description
final String CURRENT_ACCOUNT_SHARED_PREFERENCE_KEY

SharedPreference key for storing current account.

final String SINGLE_ACCOUNT_CREDENTIAL_SHARED_PREFERENCES

Name of the shared preference cache for storing SingleAccountPublicClientApplication data.

Constructor Summary

Constructor Description
SingleAccountPublicClientApplication(@NonNull final PublicClientApplicationConfiguration config)

Method Summary

Modifier and Type Method and Description
void acquireToken(@NonNull final AcquireTokenParameters acquireTokenParameters)

Acquire token interactively, will pop-up webUI. Interactive flow will skip the cache lookup. Default value for Prompt is SELECT_ACCOUNT.

Convey parameters via the AquireTokenParameters object

void acquireToken(@NonNull final Activity activity, @NonNull final String[] scopes, @NonNull final AuthenticationCallback callback)

Acquire token interactively, will pop-up webUI. Interactive flow will skip the cache lookup. Default value for Prompt is SELECT_ACCOUNT.

IAuthenticationResult acquireTokenSilent(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

IAuthenticationResult acquireTokenSilent(@NonNull final String[] scopes, @NonNull final String authority)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

void acquireTokenSilentAsync(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

void acquireTokenSilentAsync(@NonNull final String[] scopes, @NonNull final String authority, @NonNull final SilentAuthenticationCallback callback)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

CommandCallback<ILocalAuthenticationResult, BaseException> getCommandCallback( @NonNull final SilentAuthenticationCallback authenticationCallback, @NonNull final TokenParameters tokenParameters)
ICurrentAccountResult getCurrentAccount()

Gets the current account and notify if the current account changes. This method must be called whenever the application is resumed or prior to running a scheduled background operation.

void getCurrentAccountAsync(@NonNull final CurrentAccountCallback callback)
void signIn(@NonNull final Activity activity, @Nullable final String loginHint, @NonNull final String[] scopes, @NonNull final AuthenticationCallback callback)

Allows a user to sign in to your application with one of their accounts. This method may only be called once: once a user is signed in, they must first be signed out before another user may sign in. If you wish to prompt the existing user for credentials use signInAgain(Activity, String[], Prompt, AuthenticationCallback) or acquireToken(AcquireTokenParameters).

Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common or the default authority specified by you in your configuration

void signIn(@NonNull final Activity activity, @Nullable final String loginHint, @NonNull final String[] scopes, @Nullable final Prompt prompt, @NonNull final AuthenticationCallback callback)

Allows a user to sign in to your application with one of their accounts. This method may only be called once: once a user is signed in, they must first be signed out before another user may sign in. If you wish to prompt the existing user for credentials use signInAgain(Activity, String[], Prompt, AuthenticationCallback) or acquireToken(AcquireTokenParameters).

Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common or the default authority specified by you in your configuration

void signInAgain(@NonNull final Activity activity, @NonNull final String[] scopes, @Nullable final Prompt prompt, @NonNull final AuthenticationCallback callback)

Reauthorizes the current account according to the supplied scopes and prompt behavior.

Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common or the default authority specified by you in your configuration.

boolean signOut()

Signs out the current the Account and Credentials (tokens). NOTE: If a device is marked as a shared device within broker signout will be device wide.

void signOut(@NonNull final SignOutCallback callback)

Signs out the current the Account and Credentials (tokens). NOTE: If a device is marked as a shared device within broker signout will be device wide.

Inherited Members

PublicClientApplication.acquireTokenWithDeviceCode(@Nullable String[] scopes, @NonNull final DeviceCodeFlowCallback callback) IPublicClientApplication.acquireTokenWithDeviceCode(@NonNull String[] scopes, @NonNull final DeviceCodeFlowCallback callback) PublicClientApplication.buildAcquireTokenSilentParameters(@NonNull final String[] scopes, @NonNull final IAccount account, @NonNull final String authority, final boolean forceRefresh, @Nullable final ClaimsRequest claimsRequest, @NonNull final SilentAuthenticationCallback callback) PublicClientApplication.create(@NonNull final Context context, final int configFileResourceId, @NonNull final ApplicationCreatedListener listener) PublicClientApplication.create(@NonNull final Context context, @NonNull final File configFile, @NonNull final ApplicationCreatedListener listener) PublicClientApplication.create(@NonNull final Context context, @NonNull final String clientId, @Nullable final String authority, @NonNull final String redirectUri, @NonNull final ApplicationCreatedListener listener) PublicClientApplication.create(@NonNull final Context context, final int configFileResourceId) PublicClientApplication.createMultipleAccountPublicClientApplication(@NonNull final Context context, final int configFileResourceId, @NonNull final IMultipleAccountApplicationCreatedListener listener) PublicClientApplication.createMultipleAccountPublicClientApplication(@NonNull final Context context, @NonNull final File configFile, @NonNull final IMultipleAccountApplicationCreatedListener listener) PublicClientApplication.createMultipleAccountPublicClientApplication(@NonNull final Context context, @NonNull final int configFileResourceId) PublicClientApplication.createMultipleAccountPublicClientApplication(@NonNull final Context context, @NonNull final File configFile) PublicClientApplication.createSingleAccountPublicClientApplication(@NonNull final Context context, final int configFileResourceId, @NonNull final ISingleAccountApplicationCreatedListener listener) PublicClientApplication.createSingleAccountPublicClientApplication(@NonNull final Context context, @NonNull final File configFile, @NonNull final ISingleAccountApplicationCreatedListener listener) PublicClientApplication.createSingleAccountPublicClientApplication( @NonNull final Context context, final int configFileResourceId) PublicClientApplication.createSingleAccountPublicClientApplication( @NonNull final Context context, @Nullable final File configFile) PublicClientApplication.generateSignedHttpRequest(@NonNull final IAccount account, @NonNull final PoPAuthenticationScheme popParameters) PublicClientApplication.generateSignedHttpRequest(@NonNull final IAccount account, @NonNull final PoPAuthenticationScheme popParameters, @NonNull final SignedHttpRequestRequestCallback callback) PublicClientApplication.getConfiguration() ISingleAccountPublicClientApplication.getCurrentAccountAsync(final CurrentAccountCallback callback) PublicClientApplication.getMsaFamilyRefreshToken(@NonNull final String identifier) ITokenShare.getMsaFamilyRefreshToken(String identifier) PublicClientApplication.getMsaFamilyRefreshTokenWithMetadata(@NonNull final String identifier) ITokenShare.getMsaFamilyRefreshTokenWithMetadata(String identifier) PublicClientApplication.getOrgIdFamilyRefreshToken(@NonNull final String identifier) ITokenShare.getOrgIdFamilyRefreshToken(String identifier) PublicClientApplication.getOrgIdFamilyRefreshTokenWithMetadata(@NonNull final String identifier) ITokenShare.getOrgIdFamilyRefreshTokenWithMetadata(String identifier) PublicClientApplication.getSdkVersion() PublicClientApplication.homeAccountMatcher PublicClientApplication.isSharedDevice() PublicClientApplication.localAccountMatcher PublicClientApplication.mPublicClientConfiguration PublicClientApplication.mTokenShareUtility PublicClientApplication.postAuthResult(@NonNull final ILocalAuthenticationResult localAuthenticationResult, @NonNull final TokenParameters requestParameters, @NonNull final SilentAuthenticationCallback authenticationCallback) PublicClientApplication.PublicClientApplication(@NonNull final PublicClientApplicationConfiguration configFile) PublicClientApplication.saveMsaFamilyRefreshToken(@NonNull final String refreshToken) ITokenShare.saveMsaFamilyRefreshToken(String refreshToken) PublicClientApplication.saveOrgIdFamilyRefreshToken(@NonNull final String ssoStateSerializerBlob) ITokenShare.saveOrgIdFamilyRefreshToken(String ssoStateSerializerBlob) PublicClientApplication.showExpectedMsalRedirectUriInfo(Activity activity) PublicClientApplication.usernameMatcher PublicClientApplication.validateAcquireTokenParameters(AcquireTokenParameters parameters) PublicClientApplication.validateAcquireTokenSilentParameters(AcquireTokenSilentParameters parameters)

Field Details

CURRENT_ACCOUNT_SHARED_PREFERENCE_KEY

public static final String CURRENT_ACCOUNT_SHARED_PREFERENCE_KEY= "com.microsoft.identity.client.single_account_credential_cache.current_account"

SharedPreference key for storing current account.

SINGLE_ACCOUNT_CREDENTIAL_SHARED_PREFERENCES

public static final String SINGLE_ACCOUNT_CREDENTIAL_SHARED_PREFERENCES= "com.microsoft.identity.client.single_account_credential_cache"

Name of the shared preference cache for storing SingleAccountPublicClientApplication data.

Constructor Details

SingleAccountPublicClientApplication

protected SingleAccountPublicClientApplication(@NonNull final PublicClientApplicationConfiguration config)

Parameters:

config

Method Details

acquireToken

public void acquireToken(@NonNull final AcquireTokenParameters acquireTokenParameters)

Acquire token interactively, will pop-up webUI. Interactive flow will skip the cache lookup. Default value for Prompt is SELECT_ACCOUNT.

Convey parameters via the AquireTokenParameters object

Overrides:

SingleAccountPublicClientApplication.acquireToken(@NonNull final AcquireTokenParameters acquireTokenParameters)

Parameters:

acquireTokenParameters

acquireToken

public void acquireToken(@NonNull final Activity activity, @NonNull final String[] scopes, @NonNull final AuthenticationCallback callback)

Acquire token interactively, will pop-up webUI. Interactive flow will skip the cache lookup. Default value for Prompt is SELECT_ACCOUNT.

Overrides:

SingleAccountPublicClientApplication.acquireToken(@NonNull final Activity activity, @NonNull final String[] scopes, @NonNull final AuthenticationCallback callback)

Parameters:

activity - Non-null Activity that is used as the parent activity for launching the com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity.
scopes - The non-null array of scopes to be requested for the access token. MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
callback - The AuthenticationCallback to receive the result back. 1) If user cancels the flow by pressing the device back button, the result will be sent back via onCancel(). 2) If the sdk successfully receives the token back, result will be sent back via onSuccess(final IAuthenticationResult authenticationResult) 3) All the other errors will be sent back via onError(final MsalException exception).

acquireTokenSilent

public IAuthenticationResult acquireTokenSilent(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

Overrides:

SingleAccountPublicClientApplication.acquireTokenSilent(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters)

Parameters:

acquireTokenSilentParameters

acquireTokenSilent

public IAuthenticationResult acquireTokenSilent(@NonNull final String[] scopes, @NonNull final String authority)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

Overrides:

SingleAccountPublicClientApplication.acquireTokenSilent(@NonNull final String[] scopes, @NonNull final String authority)

Parameters:

scopes - The non-null array of scopes to be requested for the access token. MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
authority - Authority to issue the token.

acquireTokenSilentAsync

public void acquireTokenSilentAsync(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

Overrides:

SingleAccountPublicClientApplication.acquireTokenSilentAsync(@NonNull final AcquireTokenSilentParameters acquireTokenSilentParameters)

Parameters:

acquireTokenSilentParameters

acquireTokenSilentAsync

public void acquireTokenSilentAsync(@NonNull final String[] scopes, @NonNull final String authority, @NonNull final SilentAuthenticationCallback callback)

Perform acquire token silent call. If there is a valid access token in the cache, the sdk will return the access token; If no valid access token exists, the sdk will try to find a refresh token and use the refresh token to get a new access token. If refresh token does not exist or it fails the refresh, exception will be sent back via callback.

Overrides:

SingleAccountPublicClientApplication.acquireTokenSilentAsync(@NonNull final String[] scopes, @NonNull final String authority, @NonNull final SilentAuthenticationCallback callback)

Parameters:

scopes - The non-null array of scopes to be requested for the access token. MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter.
authority - Authority to issue the token.
callback -

SilentAuthenticationCallback that is used to send the result back. The success result will be sent back via onSuccess(final IAuthenticationResult authenticationResult). Failure case will be sent back via { onError(final MsalException exception)

getCommandCallback

protected CommandCallback getCommandCallback( @NonNull final SilentAuthenticationCallback authenticationCallback, @NonNull final TokenParameters tokenParameters)

Parameters:

authenticationCallback
tokenParameters

getCurrentAccount

public ICurrentAccountResult getCurrentAccount()

Gets the current account and notify if the current account changes. This method must be called whenever the application is resumed or prior to running a scheduled background operation.

Overrides:

SingleAccountPublicClientApplication.getCurrentAccount()

Returns:

CurrentAccountResult

getCurrentAccountAsync

public void getCurrentAccountAsync(@NonNull final CurrentAccountCallback callback)

Parameters:

callback

signIn

public void signIn(@NonNull final Activity activity, @Nullable final String loginHint, @NonNull final String[] scopes, @NonNull final AuthenticationCallback callback)

Allows a user to sign in to your application with one of their accounts. This method may only be called once: once a user is signed in, they must first be signed out before another user may sign in. If you wish to prompt the existing user for credentials use signInAgain(Activity, String[], Prompt, AuthenticationCallback) or acquireToken(AcquireTokenParameters).

Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common or the default authority specified by you in your configuration

Overrides:

SingleAccountPublicClientApplication.signIn(@NonNull final Activity activity, @Nullable final String loginHint, @NonNull final String[] scopes, @NonNull final AuthenticationCallback callback)

Parameters:

activity - Non-null Activity that is used as the parent activity for launching the com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity.
loginHint - Optional. If provided, will be used as the query parameter sent for authenticating the user, which will have the UPN pre-populated.
scopes - The non-null array of scopes to be consented to during sign in. MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter. The access token returned is for MS Graph and will allow you to query for additional information about the signed in account.
callback -

AuthenticationCallback that is used to send the result back. The success result will be sent back via onSuccess(final IAuthenticationResult authenticationResult). Failure case will be sent back via { onError(final MsalException exception)

signIn

public void signIn(@NonNull final Activity activity, @Nullable final String loginHint, @NonNull final String[] scopes, @Nullable final Prompt prompt, @NonNull final AuthenticationCallback callback)

Allows a user to sign in to your application with one of their accounts. This method may only be called once: once a user is signed in, they must first be signed out before another user may sign in. If you wish to prompt the existing user for credentials use signInAgain(Activity, String[], Prompt, AuthenticationCallback) or acquireToken(AcquireTokenParameters).

Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common or the default authority specified by you in your configuration

Overrides:

SingleAccountPublicClientApplication.signIn(@NonNull final Activity activity, @Nullable final String loginHint, @NonNull final String[] scopes, @Nullable final Prompt prompt, @NonNull final AuthenticationCallback callback)

Parameters:

activity - Non-null Activity that is used as the parent activity for launching the com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity.
loginHint - Optional. If provided, will be used as the query parameter sent for authenticating the user, which will have the UPN pre-populated.
scopes - The non-null array of scopes to be consented to during sign in. MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter. The access token returned is for MS Graph and will allow you to query for additional information about the signed in account.
prompt
callback -

AuthenticationCallback that is used to send the result back. The success result will be sent back via onSuccess(final IAuthenticationResult authenticationResult). Failure case will be sent back via { onError(final MsalException exception)

signInAgain

public void signInAgain(@NonNull final Activity activity, @NonNull final String[] scopes, @Nullable final Prompt prompt, @NonNull final AuthenticationCallback callback)

Reauthorizes the current account according to the supplied scopes and prompt behavior.

Note: The authority used to make the sign in request will be either the MSAL default: https://login.microsoftonline.com/common or the default authority specified by you in your configuration.

Overrides:

SingleAccountPublicClientApplication.signInAgain(@NonNull final Activity activity, @NonNull final String[] scopes, @Nullable final Prompt prompt, @NonNull final AuthenticationCallback callback)

Parameters:

activity - Non-null Activity that is used as the parent activity for launching the com.microsoft.identity.common.internal.providers.oauth2.AuthorizationActivity.
scopes - The non-null array of scopes to be consented to during sign in. MSAL always sends the scopes 'openid profile offline_access'. Do not include any of these scopes in the scope parameter. The access token returned is for MS Graph and will allow you to query for additional information about the signed in account.
prompt - Nullable. Indicates the type of user interaction that is required. If no argument is supplied the default behavior will be used.
callback -

AuthenticationCallback that is used to send the result back. The success result will be sent back via onSuccess(final IAuthenticationResult authenticationResult). Failure case will be sent back via onError(final MsalException exception).

signOut

public boolean signOut()

Signs out the current the Account and Credentials (tokens). NOTE: If a device is marked as a shared device within broker signout will be device wide.

Overrides:

SingleAccountPublicClientApplication.signOut()

Returns:

boolean indicating whether the account was removed successfully

signOut

public void signOut(@NonNull final SignOutCallback callback)

Signs out the current the Account and Credentials (tokens). NOTE: If a device is marked as a shared device within broker signout will be device wide.

Overrides:

SingleAccountPublicClientApplication.signOut(@NonNull final SignOutCallback callback)

Parameters:

callback - a callback to be invoked when the operation finishes.

Applies to