Skip to content

TokenParameters Subclasses Migration

fadidurah edited this page Apr 4, 2022 · 14 revisions

In an effort to increase usability and consistency throughout the MSAL API, we're prioritizing method overrides that use TokenParameters Subclasses as the only parameter. We've deprecated other overrides that use individual parameters for SCOPE, PROMPT, account, and other fields. Below is a guide to using the TokenParameters Subclasses as well as the SignInParameters class for SignIn() in SingleAccountPublicAccountApplication (note that SignInParameters is not actually a subclass of TokenParameters but serves the same purpose).

SignInParameters Class Builder

The builder() class allows user to add 5 parameters to be used for signIn flow: activity, loginHint, scope, prompt, and callback. Note that scopes can be supplied either individually as String objexct through withScope(), or all at once as a List object through withScopes().

/**
 * Encapsulates the parameters for calling {@link SingleAccountPublicClientApplication#signIn(SignInParameters)}.
 * Not a subclass of TokenParameters because it does not need fields such as Account, AccountRecord.
 *
 * Activity  -  Non-null {@link Activity} that is used as the parent activity for launching the {@link 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 list 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  -  {@link AuthenticationCallback} that is used to send the result back. The success result will be
 *              sent back via {@link AuthenticationCallback#onSuccess(IAuthenticationResult)}.
 *              Failure case will be sent back via AuthenticationCallback.onError(MsalException).
 *
 * Prompt    -  Optional. Indicates the type of user interaction that is required.
 *              If no argument is supplied the default behavior will be used (default is SELECT_ACCOUNT).
 */
final SignInParameters signInParameters = SignInParameters.builder()
                        .withActivity()
                        .withLoginHint()
                        .withScope()
                        .withScopes()
                        .withCallback(new AuthenticationCallback() {
                            @Override
                            public void onCancel() {
                                // Handle the signIn flow being cancelled
                            }
                            @Override
                            public void onSuccess(IAuthenticationResult authenticationResult) {
                                // Handle successful signIn flow with authenticationResult returned
                            }
                            @Override
                            public void onError(MsalException exception) {
                                // Handle an exception being thrown during the signIn flow
                            }
                        }).build();

New Overrides PublicClientApplication classes

Clone this wiki locally