Search in sources :

Example 6 with OAuth2

use of com.salesforce.androidsdk.auth.OAuth2 in project SalesforceMobileSDK-Android by forcedotcom.

the class OAuthWebviewHelper method onAuthFlowError.

/**
 * Called when the user facing part of the auth flow completed with an error.
 * We show the user an error and end the activity.
 *
 * @param error Error.
 * @param errorDesc Error description.
 * @param e Exception.
 */
protected void onAuthFlowError(String error, String errorDesc, Exception e) {
    SalesforceSDKLogger.e(TAG, error + ": " + errorDesc, e);
    // Broadcast a notification that the auth flow failed.
    final Intent intent = new Intent(AUTHENTICATION_FAILED_INTENT);
    if (e instanceof OAuth2.OAuthFailedException) {
        final OAuth2.OAuthFailedException exception = (OAuth2.OAuthFailedException) e;
        int statusCode = exception.getHttpStatusCode();
        intent.putExtra(HTTP_ERROR_RESPONSE_CODE_INTENT, statusCode);
        final OAuth2.TokenErrorResponse errorResponse = exception.getTokenErrorResponse();
        if (errorResponse != null) {
            final String tokenError = errorResponse.error;
            final String tokenErrorDesc = errorResponse.errorDescription;
            intent.putExtra(RESPONSE_ERROR_INTENT, tokenError);
            intent.putExtra(RESPONSE_ERROR_DESCRIPTION_INTENT, tokenErrorDesc);
        }
    }
    SalesforceSDKManager.getInstance().getAppContext().sendBroadcast(intent);
    // Displays the error in a Toast and reloads the login page after clearing cookies.
    final Toast t = Toast.makeText(webview.getContext(), error + " : " + errorDesc, Toast.LENGTH_LONG);
    webview.postDelayed(new Runnable() {

        @Override
        public void run() {
            clearCookies();
            loadLoginPage();
        }
    }, t.getDuration());
    t.show();
}
Also used : OAuth2(com.salesforce.androidsdk.auth.OAuth2) Toast(android.widget.Toast) PendingIntent(android.app.PendingIntent) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) Intent(android.content.Intent)

Example 7 with OAuth2

use of com.salesforce.androidsdk.auth.OAuth2 in project SalesforceMobileSDK-Android by forcedotcom.

the class ManagerTestCase method initRestClient.

private RestClient initRestClient() throws Exception {
    httpAccess = new HttpAccess(null, "dummy-agent");
    final TokenEndpointResponse refreshResponse = OAuth2.refreshAuthToken(httpAccess, new URI(TestCredentials.LOGIN_URL), TestCredentials.CLIENT_ID, TestCredentials.REFRESH_TOKEN, null);
    final String authToken = refreshResponse.authToken;
    final ClientInfo clientInfo = new ClientInfo(new URI(TestCredentials.INSTANCE_URL), new URI(TestCredentials.LOGIN_URL), new URI(TestCredentials.IDENTITY_URL), TestCredentials.ACCOUNT_NAME, TestCredentials.USERNAME, TestCredentials.USER_ID, TestCredentials.ORG_ID, null, null, null, null, null, null, TestCredentials.PHOTO_URL, null, null, null, null, null, null, null, null, null);
    return new RestClient(clientInfo, authToken, httpAccess, null);
}
Also used : HttpAccess(com.salesforce.androidsdk.auth.HttpAccess) RestClient(com.salesforce.androidsdk.rest.RestClient) ClientInfo(com.salesforce.androidsdk.rest.RestClient.ClientInfo) TokenEndpointResponse(com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse) URI(java.net.URI)

Aggregations

TokenEndpointResponse (com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse)5 URI (java.net.URI)5 SmallTest (androidx.test.filters.SmallTest)2 HttpAccess (com.salesforce.androidsdk.auth.HttpAccess)2 OAuth2 (com.salesforce.androidsdk.auth.OAuth2)2 IdServiceResponse (com.salesforce.androidsdk.auth.OAuth2.IdServiceResponse)2 ClientInfo (com.salesforce.androidsdk.rest.RestClient.ClientInfo)2 Before (org.junit.Before)2 Test (org.junit.Test)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Toast (android.widget.Toast)1 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)1 RestClient (com.salesforce.androidsdk.rest.RestClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1