Search in sources :

Example 11 with ClientManager

use of com.salesforce.androidsdk.rest.ClientManager in project SalesforceMobileSDK-Android by forcedotcom.

the class SalesforceSDKManager method logout.

/**
 * Destroys the stored authentication credentials (removes the account)
 * and, if requested, restarts the app.
 *
 * @param frontActivity Front activity.
 * @param showLoginPage If true, displays the login page after removing the account.
 */
public void logout(Activity frontActivity, final boolean showLoginPage) {
    final ClientManager clientMgr = new ClientManager(context, getAccountType(), null, shouldLogoutWhenTokenRevoked());
    final Account account = clientMgr.getAccount();
    logout(account, frontActivity, showLoginPage);
}
Also used : Account(android.accounts.Account) UserAccount(com.salesforce.androidsdk.accounts.UserAccount) ClientManager(com.salesforce.androidsdk.rest.ClientManager)

Example 12 with ClientManager

use of com.salesforce.androidsdk.rest.ClientManager in project SalesforceMobileSDK-Android by forcedotcom.

the class SalesforceActivityDelegate method onResume.

/**
 * Brings up ScreenLock if needed
 * Build RestClient if requested and then calls activity.onResume(restClient)
 * Otherwise calls activity.onResume(null)
 *
 * @param buildRestClient
 */
public void onResume(boolean buildRestClient) {
    // Brings up the ScreenLock if needed.
    if (buildRestClient) {
        // Gets login options.
        final String accountType = SalesforceSDKManager.getInstance().getAccountType();
        final ClientManager.LoginOptions loginOptions = SalesforceSDKManager.getInstance().getLoginOptions();
        // Gets a rest client.
        new ClientManager(SalesforceSDKManager.getInstance().getAppContext(), accountType, loginOptions, SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked()).getRestClient(activity, new ClientManager.RestClientCallback() {

            @Override
            public void authenticatedRestClient(RestClient client) {
                if (client == null) {
                    SalesforceSDKManager.getInstance().logout(activity);
                    return;
                }
                ((SalesforceActivityInterface) activity).onResume(client);
                // Lets observers know that rendition is complete.
                EventsObservable.get().notifyEvent(EventsObservable.EventType.RenditionComplete);
            }
        });
    } else {
        ((SalesforceActivityInterface) activity).onResume(null);
    }
}
Also used : ClientManager(com.salesforce.androidsdk.rest.ClientManager) RestClient(com.salesforce.androidsdk.rest.RestClient)

Example 13 with ClientManager

use of com.salesforce.androidsdk.rest.ClientManager in project SalesforceMobileSDK-Android by forcedotcom.

the class IDPRequestHandler method buildRestClient.

private void buildRestClient() {
    final Context context = SalesforceSDKManager.getInstance().getAppContext();
    final BootConfig bootConfig = BootConfig.getBootConfig(context);
    final String idpCallbackUrl = bootConfig.getOauthRedirectURI();
    final String idpClientId = bootConfig.getRemoteAccessConsumerKey();
    final String[] idpScopes = bootConfig.getOauthScopes();
    final ClientManager.LoginOptions loginOptions = new ClientManager.LoginOptions(loginUrl, idpCallbackUrl, idpClientId, idpScopes);
    final String idpAccountType = SalesforceSDKManager.getInstance().getAccountType();
    final ClientManager clientManager = new ClientManager(context, idpAccountType, loginOptions, false);
    restClient = clientManager.peekRestClient(userAccount);
}
Also used : Context(android.content.Context) BootConfig(com.salesforce.androidsdk.config.BootConfig) ClientManager(com.salesforce.androidsdk.rest.ClientManager)

Example 14 with ClientManager

use of com.salesforce.androidsdk.rest.ClientManager in project SalesforceMobileSDK-Android by forcedotcom.

the class ManagerTestCase method setUp.

public void setUp() throws Exception {
    targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
    apiVersion = ApiVersionStrings.getVersionNumber(targetContext);
    final Application app = Instrumentation.newApplication(TestForceApp.class, targetContext);
    InstrumentationRegistry.getInstrumentation().callApplicationOnCreate(app);
    TestCredentials.init(InstrumentationRegistry.getInstrumentation().getContext());
    eq = new EventsListenerQueue();
    if (MobileSyncSDKManager.getInstance() == null) {
        eq.waitForEvent(EventType.AppCreateComplete, 5000);
    }
    final LoginOptions loginOptions = new LoginOptions(TestCredentials.LOGIN_URL, TEST_CALLBACK_URL, TestCredentials.CLIENT_ID, TEST_SCOPES);
    final ClientManager clientManager = new ClientManager(targetContext, TestCredentials.ACCOUNT_TYPE, loginOptions, true);
    clientManager.createNewAccount(TestCredentials.ACCOUNT_NAME, TestCredentials.USERNAME, TestCredentials.REFRESH_TOKEN, TEST_AUTH_TOKEN, TestCredentials.INSTANCE_URL, TestCredentials.LOGIN_URL, TestCredentials.IDENTITY_URL, TestCredentials.CLIENT_ID, TestCredentials.ORG_ID, TestCredentials.USER_ID, null, null, null, null, null, null, TestCredentials.PHOTO_URL, null, null, null, null, null, null, null, null, null);
    SyncManager.reset();
    sdkManager = MobileSyncSDKManager.getInstance();
    smartStore = sdkManager.getSmartStore();
    globalSmartStore = sdkManager.getGlobalSmartStore();
    syncManager = SyncManager.getInstance();
    globalSyncManager = SyncManager.getInstance(null, null, globalSmartStore);
    restClient = initRestClient();
    syncManager.setRestClient(restClient);
    MobileSyncLogger.setLogLevel(SalesforceLogger.Level.DEBUG);
}
Also used : LoginOptions(com.salesforce.androidsdk.rest.ClientManager.LoginOptions) ClientManager(com.salesforce.androidsdk.rest.ClientManager) Application(android.app.Application) EventsListenerQueue(com.salesforce.androidsdk.util.test.EventsListenerQueue)

Aggregations

ClientManager (com.salesforce.androidsdk.rest.ClientManager)14 Context (android.content.Context)4 UserAccount (com.salesforce.androidsdk.accounts.UserAccount)4 Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 Application (android.app.Application)2 UserAccountManager (com.salesforce.androidsdk.accounts.UserAccountManager)2 LoginOptions (com.salesforce.androidsdk.rest.ClientManager.LoginOptions)2 RestClient (com.salesforce.androidsdk.rest.RestClient)2 EventsListenerQueue (com.salesforce.androidsdk.util.test.EventsListenerQueue)2 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 SmallTest (androidx.test.filters.SmallTest)1 UserAccountTest (com.salesforce.androidsdk.accounts.UserAccountTest)1 SalesforceAnalyticsManager (com.salesforce.androidsdk.analytics.SalesforceAnalyticsManager)1 AnalyticsManager (com.salesforce.androidsdk.analytics.manager.AnalyticsManager)1 DeviceAppAttributes (com.salesforce.androidsdk.analytics.model.DeviceAppAttributes)1 BootConfig (com.salesforce.androidsdk.config.BootConfig)1 AccMgrAuthTokenProvider (com.salesforce.androidsdk.rest.ClientManager.AccMgrAuthTokenProvider)1 ClientInfo (com.salesforce.androidsdk.rest.RestClient.ClientInfo)1