Search in sources :

Example 1 with TokenEndpointResponse

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

the class RestClientTest method setUp.

@Before
public void setUp() throws Exception {
    TestCredentials.init(InstrumentationRegistry.getInstrumentation().getContext());
    httpAccess = new HttpAccess(null, "dummy-agent");
    TokenEndpointResponse refreshResponse = OAuth2.refreshAuthToken(httpAccess, new URI(TestCredentials.LOGIN_URL), TestCredentials.CLIENT_ID, TestCredentials.REFRESH_TOKEN, null);
    authToken = refreshResponse.authToken;
    instanceUrl = refreshResponse.instanceUrl;
    testOauthKeys = new ArrayList<>();
    testOauthKeys.add(TEST_CUSTOM_KEY);
    testOauthValues = new HashMap<>();
    testOauthValues.put(TEST_CUSTOM_KEY, TEST_CUSTOM_VALUE);
    SalesforceSDKManager.getInstance().setAdditionalOauthKeys(testOauthKeys);
    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, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_DISPLAY_NAME, TEST_EMAIL, TestCredentials.PHOTO_URL, TEST_THUMBNAIL_URL, testOauthValues, null, null, null, null, null, null, null);
    restClient = new RestClient(clientInfo, authToken, httpAccess, null);
}
Also used : HttpAccess(com.salesforce.androidsdk.auth.HttpAccess) ClientInfo(com.salesforce.androidsdk.rest.RestClient.ClientInfo) TokenEndpointResponse(com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse) URI(java.net.URI) Before(org.junit.Before)

Example 2 with TokenEndpointResponse

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

the class HttpAccessTest method setUp.

@Before
public void setUp() throws Exception {
    TestCredentials.init(InstrumentationRegistry.getInstrumentation().getContext());
    final HttpAccess httpAccess = new HttpAccess(null, "dummy-agent");
    okHttpClient = httpAccess.getOkHttpClient();
    resourcesUrl = HttpUrl.parse(TestCredentials.INSTANCE_URL + "/services/data/" + TestCredentials.API_VERSION + "/");
    TokenEndpointResponse refreshResponse = OAuth2.refreshAuthToken(httpAccess, new URI(TestCredentials.LOGIN_URL), TestCredentials.CLIENT_ID, TestCredentials.REFRESH_TOKEN, null);
    headers = new Headers.Builder().add("Content-Type", "application/json").add("Authorization", "OAuth " + refreshResponse.authToken).build();
}
Also used : TokenEndpointResponse(com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse) URI(java.net.URI) Before(org.junit.Before)

Example 3 with TokenEndpointResponse

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

the class OAuth2Test method testRefreshAuthToken.

/**
 * Testing refreshAuthToken. Call refresh token, then try out the auth token by calling /services/data/vXX.
 *
 * @throws IOException See {@link IOException}.
 * @throws URISyntaxException See {@link URISyntaxException}.
 * @throws OAuthFailedException See {@link OAuthFailedException}.
 */
@Test
public void testRefreshAuthToken() throws IOException, OAuthFailedException, URISyntaxException {
    // Get an auth token using the refresh token.
    TokenEndpointResponse refreshResponse = OAuth2.refreshAuthToken(httpAccess, new URI(TestCredentials.LOGIN_URL), TestCredentials.CLIENT_ID, TestCredentials.REFRESH_TOKEN, null);
    Assert.assertNotNull("Auth token should not be null", refreshResponse.authToken);
    // Let's try it out.
    Request request = new Request.Builder().addHeader("Content-Type", "application/json").addHeader("Authorization", "Bearer " + refreshResponse.authToken).url(TestCredentials.INSTANCE_URL + "/services/data/" + ApiVersionStrings.VERSION_NUMBER).get().build();
    Response resourcesResponse = httpAccess.getOkHttpClient().newCall(request).execute();
    Assert.assertEquals("HTTP response status code should have been 200 (OK)", HttpURLConnection.HTTP_OK, resourcesResponse.code());
}
Also used : TokenEndpointResponse(com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse) Response(okhttp3.Response) IdServiceResponse(com.salesforce.androidsdk.auth.OAuth2.IdServiceResponse) Request(okhttp3.Request) TokenEndpointResponse(com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse) URI(java.net.URI) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 4 with TokenEndpointResponse

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

the class OAuth2Test method testCallIdentityService.

/**
 * Testing callIdentityService. Call refresh token then call out to identity service and
 * check that username returned match the one in TestCredentials.
 *
 * @throws IOException See {@link IOException}.
 * @throws OAuthFailedException See {@link OAuthFailedException}.
 * @throws URISyntaxException See {@link URISyntaxException}.
 */
@Test
public void testCallIdentityService() throws IOException, OAuthFailedException, URISyntaxException {
    // Get an auth token using the refresh token
    TokenEndpointResponse refreshResponse = OAuth2.refreshAuthToken(httpAccess, new URI(TestCredentials.LOGIN_URL), TestCredentials.CLIENT_ID, TestCredentials.REFRESH_TOKEN, null);
    Assert.assertNotNull("Auth token should not be null", refreshResponse.authToken);
    // Now let's call the identity service
    IdServiceResponse id = OAuth2.callIdentityService(httpAccess, TestCredentials.INSTANCE_URL + "/id/" + TestCredentials.ORG_ID + "/" + TestCredentials.USER_ID, refreshResponse.authToken);
    Assert.assertEquals("Wrong username returned", TestCredentials.USERNAME, id.username);
    Assert.assertEquals("Wrong pinLength returned", -1, id.pinLength);
    Assert.assertEquals("Wrong screenLockTimeout returned", -1, id.screenLockTimeout);
    Assert.assertTrue("Wrong biometricUnlockAllowed returned", id.biometricUnlockAllowed);
}
Also used : IdServiceResponse(com.salesforce.androidsdk.auth.OAuth2.IdServiceResponse) TokenEndpointResponse(com.salesforce.androidsdk.auth.OAuth2.TokenEndpointResponse) URI(java.net.URI) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 5 with TokenEndpointResponse

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

the class LoginActivity method completeAuthFlow.

private void completeAuthFlow(Intent intent) {
    final Uri uri = intent.getData();
    final Map<String, String> params = UriFragmentParser.parse(uri);
    final String error = params.get("error");
    if (error != null) {
        final String errorDesc = params.get("error_description");
        webviewHelper.onAuthFlowError(error, errorDesc, null);
    } else {
        final OAuth2.TokenEndpointResponse tr = new OAuth2.TokenEndpointResponse(params);
        webviewHelper.onAuthFlowComplete(tr);
    }
}
Also used : OAuth2(com.salesforce.androidsdk.auth.OAuth2) Uri(android.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 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 Uri (android.net.Uri)1 OAuth2 (com.salesforce.androidsdk.auth.OAuth2)1 RestClient (com.salesforce.androidsdk.rest.RestClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1