use of com.salesforce.androidsdk.rest.RestClient in project SalesforceMobileSDK-Android by forcedotcom.
the class SalesforceReactActivity method authenticate.
/**
* Method called from bridge to authenticate.
*
* @param successCallback Success callback.
* @param errorCallback Error callback.
*/
public void authenticate(final Callback successCallback, final Callback errorCallback) {
SalesforceReactLogger.i(TAG, "authenticate called");
clientManager.getRestClient(this, new RestClientCallback() {
@Override
public void authenticatedRestClient(RestClient client) {
SalesforceReactActivity.this.setRestClient(client);
getAuthCredentials(successCallback, errorCallback);
}
});
}
use of com.salesforce.androidsdk.rest.RestClient 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);
}
use of com.salesforce.androidsdk.rest.RestClient in project SalesforceMobileSDK-Android by forcedotcom.
the class SalesforceDroidGapActivity method authenticate.
/**
* Get a RestClient and refresh the auth token
*
* @param callbackContext when not null credentials/errors are sent through to callbackContext.success()/error()
*/
public void authenticate(final CallbackContext callbackContext) {
SalesforceHybridLogger.i(TAG, "authenticate called");
clientManager.getRestClient(this, new RestClientCallback() {
@Override
public void authenticatedRestClient(RestClient client) {
if (client == null) {
SalesforceHybridLogger.i(TAG, "authenticate callback triggered with null client");
logout(null);
} else {
SalesforceHybridLogger.i(TAG, "authenticate callback triggered with actual client");
SalesforceDroidGapActivity.this.client = client;
/*
* Do a cheap REST call to refresh the access token if needed.
* If the login took place a while back (e.g. the already logged
* in application was restarted), then the returned session ID
* (access token) might be stale. This is not an issue if one
* uses exclusively RestClient for calling the server because
* it takes care of refreshing the access token when needed,
* but a stale session ID will cause the WebView to redirect
* to the web login.
*/
SalesforceDroidGapActivity.this.client.sendAsync(RestRequest.getRequestForUserInfo(), new AsyncRequestCallback() {
@Override
public void onSuccess(RestRequest request, RestResponse response) {
runOnUiThread(new Runnable() {
@Override
public void run() {
/*
* The client instance being used here needs to be
* refreshed, to ensure we use the new access token.
*/
SalesforceDroidGapActivity.this.client = SalesforceDroidGapActivity.this.clientManager.peekRestClient();
getAuthCredentials(callbackContext);
}
});
}
@Override
public void onError(Exception exception) {
if (callbackContext != null) {
callbackContext.error(exception.getMessage());
}
}
});
}
}
});
}
Aggregations