com.microsoft.identity.client.AuthenticationCallback Java Examples

The following examples show how to use com.microsoft.identity.client.AuthenticationCallback. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: AuthenticationManager.java    From android-java-snippets-rest-sample with MIT License 4 votes vote down vote up
/**
 * Authenticates the user and lets the user authorize the app for the requested permissions.
 * An authentication token is returned via the getAuthInteractiveCallback method
 * @param authenticationCallback
 */
public void callAcquireToken(final AuthenticationCallback authenticationCallback) {
    mActivityCallback = authenticationCallback;
    mPublicClientApplication.acquireToken(
            mActivity, mScopes, getAuthInteractiveCallback());
}
 
Example #9
Source File: AuthenticationManager.java    From android-java-snippets-rest-sample with MIT License 4 votes vote down vote up
public void callAcquireTokenSilent(IAccount user, boolean forceRefresh, AuthenticationCallback authenticationCallback) {
    mActivityCallback = authenticationCallback;
    mPublicClientApplication.acquireTokenSilentAsync(mScopes, user, null, forceRefresh, getAuthSilentCallback());
}