use of com.trovebox.android.app.net.account.AccountTroveboxResponse in project mobile-android by photo.
the class AccountTroveboxApiTest method testSignInViaGoogle.
public void testSignInViaGoogle() throws ClientProtocolException, IllegalStateException, IOException, JSONException, UserRecoverableAuthException, GoogleAuthException, GeneralSecurityException {
// how to setup environment
// http://android-developers.blogspot.in/2013/01/verifying-back-end-calls-from-android.html
String[] names = getAccountNames();
assertTrue(names != null && names.length > 0);
String accountName = names[0];
String audience = CommonUtils.getStringResource(R.string.google_auth_server_client_id);
String SCOPE = "audience:server:client_id:" + audience;
String tokenString = GoogleAuthUtil.getToken(getContext(), accountName, SCOPE);
// token verification part, this should be done on server side
GoogleIdTokenVerifier mVerifier;
JsonFactory mJFactory;
NetHttpTransport transport = new NetHttpTransport();
mJFactory = new GsonFactory();
mVerifier = new GoogleIdTokenVerifier(transport, mJFactory);
GoogleIdToken token = GoogleIdToken.parse(mJFactory, tokenString);
assertTrue(mVerifier.verify(token));
GoogleIdToken.Payload tempPayload = token.getPayload();
assertTrue(tempPayload.getAudience().equals(audience));
assertNotNull(tempPayload.getEmail());
// end of token verification part
AccountTroveboxResponse response = mApi.signInViaGoogle(tokenString);
assertNotNull(response);
assertTrue(response.isSuccess());
Credentials[] credentials = response.getCredentials();
assertNotNull(credentials);
assertTrue(credentials.length > 0);
Credentials c = credentials[0];
checkoAuthString(c.getoAuthConsumerKey());
checkoAuthString(c.getoAuthConsumerSecret());
checkoAuthString(c.getoAuthToken());
checkoAuthString(c.getoAuthConsumerSecret());
}
use of com.trovebox.android.app.net.account.AccountTroveboxResponse in project mobile-android by photo.
the class AccountTroveboxResponseTest method testSimpleResponse.
public void testSimpleResponse() throws JSONException {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_login_simple);
AccountTroveboxResponse response = new AccountTroveboxResponse(RequestType.UNKNOWN, json);
assertNotNull(response);
assertEquals(200, response.getCode());
Credentials[] credentials = response.getCredentials();
assertNotNull(credentials);
assertTrue(credentials.length == 1);
CredentialsTest.checkCredentials(credentials[0], "hello@trovebox.com");
}
use of com.trovebox.android.app.net.account.AccountTroveboxResponse in project mobile-android by photo.
the class AccountTroveboxResponseTest method testMultiResponse.
public void testMultiResponse() throws JSONException {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_login_multiple);
AccountTroveboxResponse response = new AccountTroveboxResponse(RequestType.UNKNOWN, json);
assertNotNull(response);
assertEquals(200, response.getCode());
Credentials[] credentials = response.getCredentials();
assertNotNull(credentials);
assertTrue(credentials.length == 2);
CredentialsTest.checkCredentials(credentials[0], "hello@trovebox.com");
CredentialsTest.checkCredentials(credentials[1], "hello2@trovebox.com");
}
use of com.trovebox.android.app.net.account.AccountTroveboxResponse in project mobile-android by photo.
the class AccountTroveboxResponseTest method testMultiResponseV2.
public void testMultiResponseV2() throws JSONException {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_login_multiple_v2);
AccountTroveboxResponse response = new AccountTroveboxResponse(RequestType.UNKNOWN, json);
assertNotNull(response);
assertEquals(200, response.getCode());
Credentials[] credentials = response.getCredentials();
assertNotNull(credentials);
assertTrue(credentials.length == 3);
CredentialsTest.checkCredentialsV2(credentials[0], "hello@trovebox.com", "http://test.trovebox.com", Credentials.OWNER_TYPE);
CredentialsTest.checkCredentialsV2(credentials[1], "hellox@trovebox.com", "http://test2.trovebox.com", Credentials.ADMIN_TYPE);
CredentialsTest.checkCredentialsV2(credentials[2], "hellox2@trovebox.com", "http://test3.trovebox.com", Credentials.GROUP_TYPE);
}
Aggregations