com.microsoft.identity.client.exception.MsalException Java Examples

The following examples show how to use com.microsoft.identity.client.exception.MsalException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectActivity.java    From android-java-connect-sample with MIT License 6 votes vote down vote up
@Override
public void onError(MsalException exception) {
    // Check the exception type.
    if (exception instanceof MsalClientException) {
        // This means errors happened in the sdk itself, could be network, Json parse, etc. Check MsalError.java
        // for detailed list of the errors.
        showMessage(exception.getMessage());
        showConnectErrorUI(exception.getMessage());
    } else if (exception instanceof MsalServiceException) {
        // This means something is wrong when the sdk is communication to the service, mostly likely it's the client
        // configuration.
        showMessage(exception.getMessage());
        showConnectErrorUI(exception.getMessage());
    } else if (exception instanceof MsalUiRequiredException) {
        // This explicitly indicates that developer needs to prompt the user, it could be refresh token is expired, revoked
        // or user changes the password; or it could be that no token was found in the token cache.
        AuthenticationManager mgr = AuthenticationManager.getInstance();


        mgr.callAcquireToken(ConnectActivity.this, this);
    }
}
 
Example #2
Source File: MicrosoftProvider.java    From SEAL-Demo with MIT License 5 votes vote down vote up
/**
 * Get an AuthenticationCallback object to handle the result of the Microsoft login
 */
private AuthenticationCallback getAuthInteractiveCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
            /* Successfully got a token, use it to call a protected resource */
            Log.e(TAG, " MSA signInResult:= " + authenticationResult.getAccessToken());
            mAuthResult = authenticationResult;
            mSignInActivity.getProgressBar().setVisibility(View.VISIBLE);
            callGraphAPI();
        }

        @Override
        public void onError(MsalException exception) {
            /* Failed to acquireToken */

            if (exception instanceof MsalClientException) {
                /* Exception inside MSAL, more info inside MsalError.java */
                Log.e(TAG, "MSA signInResult: error =" + exception.getMessage());
            } else if (exception instanceof MsalServiceException) {
                /* Exception when communicating with the STS, likely config issue */
                Log.e(TAG, "MSA signInResult:error =" + exception.getMessage());
            }
        }

        @Override
        public void onCancel() {
            /* User canceled the authentication */
        }
    };
}
 
Example #3
Source File: AuthenticationManager.java    From android-java-connect-sample with MIT License 5 votes vote down vote up
private AuthenticationCallback getAuthSilentCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
        /* Successfully got a token, call Graph now */
            Log.d(TAG, "Successfully authenticated");

        /* Store the authResult */
            mAuthResult = authenticationResult;

            //invoke UI callback
            if (mActivityCallback != null)
                mActivityCallback.onSuccess(mAuthResult);
        }

        @Override
        public void onError(MsalException exception) {
        /* Failed to acquireToken */
            Log.d(TAG, "Authentication failed: " + exception.toString());
            if (mActivityCallback != null)
                mActivityCallback.onError(exception);
        }

        @Override
        public void onCancel() {
        /* User canceled the authentication */
            Log.d(TAG, "User cancelled login.");
        }
    };
}
 
Example #4
Source File: AuthenticationManager.java    From android-java-connect-sample with MIT License 5 votes vote down vote up
private AuthenticationCallback getAuthInteractiveCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
        /* Successfully got a token, call graph now */
            Log.d(TAG, "Successfully authenticated");
            Log.d(TAG, "ID Token: " + authenticationResult.getIdToken());

        /* Store the auth result */
            mAuthResult = authenticationResult;
            if (mActivityCallback != null)
                mActivityCallback.onSuccess(mAuthResult);
        }

        @Override
        public void onError(MsalException exception) {
        /* Failed to acquireToken */
            Log.d(TAG, "Authentication failed: " + exception.toString());
            if (mActivityCallback != null)
                mActivityCallback.onError(exception);
        }

        @Override
        public void onCancel() {
        /* User canceled the authentication */
            Log.d(TAG, "User cancelled login.");
            if (mActivityCallback != null)
                mActivityCallback.onCancel();
        }
    };
}
 
Example #5
Source File: SignInActivity.java    From android-java-snippets-sample with MIT License 5 votes vote down vote up
@Override
public void onError(MsalException e) {
    e.printStackTrace();

    //Show the localized message supplied with the exception or
    //or a default message from the string resources if a
    //localized message cannot be obtained
    String msg;
    if (null == (msg = e.getLocalizedMessage())) {
        msg = getString(sign_in_err);
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    } else {
        mDiagnosticsTxt.setText(msg);
        mDiagnosticsLayout.setVisibility(VISIBLE);
    }

    if (e instanceof MsalClientException) {
        // This means errors happened in the sdk itself, could be network, Json parse, etc. Check MsalError.java
        // for detailed list of the errors.

        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();

    } else if (e instanceof MsalServiceException) {
        // This means something is wrong when the sdk is communication to the service, mostly likely it's the client
        // configuration.
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();

    } else if (e instanceof MsalUiRequiredException) {
        // This explicitly indicates that developer needs to prompt the user, it could be refresh token is expired, revoked
        // or user changes the password; or it could be that no token was found in the token cache.
        AuthenticationManager mgr = AuthenticationManager.getInstance();
        mgr.callAcquireToken(SignInActivity.this, this);
    }

}
 
Example #6
Source File: AuthenticationManager.java    From android-java-snippets-sample with MIT License 5 votes vote down vote up
private AuthenticationCallback getAuthSilentCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
        /* Successfully got a token, call Graph now */
            Log.d(TAG, "Successfully authenticated");

        /* Store the authResult */
            mAuthResult = authenticationResult;

            //invoke UI callback
            if (mActivityCallback != null)
                mActivityCallback.onSuccess(mAuthResult);
        }

        @Override
        public void onError(MsalException exception) {
        /* Failed to acquireToken */
            Log.d(TAG, "Authentication failed: " + exception.toString());
            if (mActivityCallback != null)
                mActivityCallback.onError(exception);
        }

        @Override
        public void onCancel() {
        /* User canceled the authentication */
            Log.d(TAG, "User cancelled login.");
        }
    };
}
 
Example #7
Source File: AuthenticationManager.java    From android-java-snippets-sample with MIT License 5 votes vote down vote up
private AuthenticationCallback getAuthInteractiveCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
        /* Successfully got a token, call graph now */
            Log.d(TAG, "Successfully authenticated");
            Log.d(TAG, "ID Token: " + authenticationResult.getIdToken());

        /* Store the auth result */
            mAuthResult = authenticationResult;
            if (mActivityCallback != null)
                mActivityCallback.onSuccess(mAuthResult);
        }

        @Override
        public void onError(MsalException exception) {
        /* Failed to acquireToken */
            Log.d(TAG, "Authentication failed: " + exception.toString());
            if (mActivityCallback != null)
                mActivityCallback.onError(exception);
        }

        @Override
        public void onCancel() {
        /* User canceled the authentication */
            Log.d(TAG, "User cancelled login.");
            if (mActivityCallback != null)
                mActivityCallback.onCancel();
        }
    };
}
 
Example #8
Source File: SignInActivity.java    From android-java-snippets-rest-sample with MIT License 5 votes vote down vote up
@Override
public void onError(MsalException exception) {
    exception.printStackTrace();

    //Show the localized message supplied with the exception or
    //or a default message from the string resources if a
    //localized message cannot be obtained
    String msg;
    if (null == (msg = exception.getLocalizedMessage())) {
        msg = getString(signin_err);
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    } else {
        mDiagnosticsTxt.setText(msg);
        mDiagnosticsLayout.setVisibility(VISIBLE);
    }
    if (exception instanceof MsalClientException) {
        // This means errors happened in the sdk itself, could be network, Json parse, etc. Check MsalError.java
        // for detailed list of the errors.

        Toast.makeText(this, exception.getMessage(), Toast.LENGTH_SHORT).show();

    } else if (exception instanceof MsalServiceException) {
        // This means something is wrong when the sdk is communication to the service, mostly likely it's the client
        // configuration.
        Toast.makeText(this, exception.getMessage(), Toast.LENGTH_SHORT).show();

    } else if (exception instanceof MsalUiRequiredException) {
        // This explicitly indicates that developer needs to prompt the user, it could be refresh token is expired, revoked
        // or user changes the password; or it could be that no token was found in the token cache.

        mAuthenticationManager.callAcquireToken( this);
    }
}
 
Example #9
Source File: AuthenticationManager.java    From android-java-snippets-rest-sample with MIT License 5 votes vote down vote up
private AuthenticationCallback getAuthSilentCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
            /* Successfully got a token, call Graph now */
            Log.d(TAG, "Successfully authenticated");

            /* Store the authResult */
            mAuthResult = authenticationResult;

            //invoke UI callback
            if (mActivityCallback != null)
                mActivityCallback.onSuccess(mAuthResult);
        }

        @Override
        public void onError(MsalException exception) {
            /* Failed to acquireToken */
            Log.d(TAG, "Authentication failed: " + exception.toString());
            if (mActivityCallback != null)
                mActivityCallback.onError(exception);
        }

        @Override
        public void onCancel() {
            /* User canceled the authentication */
            Log.d(TAG, "User cancelled login.");
        }
    };
}
 
Example #10
Source File: AuthenticationManager.java    From android-java-snippets-rest-sample with MIT License 5 votes vote down vote up
private AuthenticationCallback getAuthInteractiveCallback() {
    return new AuthenticationCallback() {
        @Override
        public void onSuccess(AuthenticationResult authenticationResult) {
            /* Successfully got a token, call graph now */
            Log.d(TAG, "Successfully authenticated");
            Log.d(TAG, "ID Token: " + authenticationResult.getIdToken());

            /* Store the auth result */
            mAuthResult = authenticationResult;
            if (mActivityCallback != null)
                mActivityCallback.onSuccess(mAuthResult);
        }

        @Override
        public void onError(MsalException exception) {
            /* Failed to acquireToken */
            Log.d(TAG, "Authentication failed: " + exception.toString());
            if (mActivityCallback != null)
                mActivityCallback.onError(exception);
        }

        @Override
        public void onCancel() {
            /* User canceled the authentication */
            Log.d(TAG, "User cancelled login.");
            if (mActivityCallback != null)
                mActivityCallback.onCancel();
        }
    };
}
 
Example #11
Source File: MSALAuthenticationCallback.java    From android-java-connect-sample with MIT License votes vote down vote up
void onError(MsalException exception); 
Example #12
Source File: MSALAuthenticationCallback.java    From android-java-snippets-sample with MIT License votes vote down vote up
void onError(MsalException exception);