Search in sources :

Example 1 with Credentials

use of com.trovebox.android.common.model.Credentials in project mobile-android by photo.

the class LoginUtils method processSuccessfulLoginResult.

/**
     * Common successful AccountTroveboxResult processor
     * 
     * @param result
     * @param fragmentAccessor
     * @param activity
     */
public static void processSuccessfulLoginResult(AccountTroveboxResponse result, ObjectAccessor<? extends LoginActionHandler> fragmentAccessor, Activity activity) {
    Credentials[] credentials = result.getCredentials();
    if (credentials.length == 1) {
        CommonUtils.debug(TAG, "processSuccessfulLoginResult: found one login credentials");
        performLogin(fragmentAccessor, credentials[0]);
    } else {
        CommonUtils.debug(TAG, "processSuccessfulLoginResult: found multiple login credentials");
        Intent intent = new Intent(activity, SelectAccountActivity.class);
        intent.putParcelableArrayListExtra(SelectAccountActivity.CREDENTIALS, new ArrayList<Credentials>(Arrays.asList(credentials)));
        activity.startActivity(intent);
    }
}
Also used : Intent(android.content.Intent) Credentials(com.trovebox.android.common.model.Credentials)

Example 2 with Credentials

use of com.trovebox.android.common.model.Credentials 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());
}
Also used : GsonFactory(com.google.api.client.json.gson.GsonFactory) AccountTroveboxResponse(com.trovebox.android.app.net.account.AccountTroveboxResponse) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleIdTokenVerifier(com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier) JsonFactory(com.google.api.client.json.JsonFactory) GoogleIdToken(com.google.api.client.googleapis.auth.oauth2.GoogleIdToken) Credentials(com.trovebox.android.common.model.Credentials)

Example 3 with Credentials

use of com.trovebox.android.common.model.Credentials in project mobile-android by photo.

the class CredentialsTest method testCredentialsParcelableV2.

public void testCredentialsParcelableV2() throws JSONException {
    Credentials c;
    JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_credentials_v2);
    c = new Credentials(json);
    checkCredentialsV2(c, "hellox2@trovebox.com", "http://test3.trovebox.com", Credentials.GROUP_TYPE);
    ProfileInformationTest.checkProfileInformation2(c.getProfileInformation(), json.getJSONObject("profile").getJSONObject("permission").toString());
    Parcel parcel = Parcel.obtain();
    c.writeToParcel(parcel, 0);
    // done writing, now reset parcel for reading
    parcel.setDataPosition(0);
    // finish round trip
    Credentials createFromParcel = Credentials.CREATOR.createFromParcel(parcel);
    checkCredentialsV2(createFromParcel, "hellox2@trovebox.com", "http://test3.trovebox.com", Credentials.GROUP_TYPE);
    ProfileInformationTest.checkProfileInformation2(createFromParcel.getProfileInformation(), json.getJSONObject("profile").getJSONObject("permission").toString());
}
Also used : JSONObject(org.json.JSONObject) Parcel(android.os.Parcel) Credentials(com.trovebox.android.common.model.Credentials)

Example 4 with Credentials

use of com.trovebox.android.common.model.Credentials in project mobile-android by photo.

the class CredentialsTest method testFromJson.

public void testFromJson() {
    Credentials c;
    try {
        JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_credentials);
        c = new Credentials(json);
    } catch (JSONException e) {
        throw new AssertionError("This exception should not be thrown!");
    }
    checkCredentials(c, "hello@trovebox.com");
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Credentials(com.trovebox.android.common.model.Credentials)

Example 5 with Credentials

use of com.trovebox.android.common.model.Credentials 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");
}
Also used : AccountTroveboxResponse(com.trovebox.android.app.net.account.AccountTroveboxResponse) JSONObject(org.json.JSONObject) Credentials(com.trovebox.android.common.model.Credentials)

Aggregations

Credentials (com.trovebox.android.common.model.Credentials)8 JSONObject (org.json.JSONObject)6 AccountTroveboxResponse (com.trovebox.android.app.net.account.AccountTroveboxResponse)4 Parcel (android.os.Parcel)2 JSONException (org.json.JSONException)2 Intent (android.content.Intent)1 GoogleIdToken (com.google.api.client.googleapis.auth.oauth2.GoogleIdToken)1 GoogleIdTokenVerifier (com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1 GsonFactory (com.google.api.client.json.gson.GsonFactory)1