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);
}
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();
}
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());
}
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);
}
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);
}
}
Aggregations