Search in sources :

Example 1 with AuthParamsBuilder

use of com.zype.android.webapi.builder.AuthParamsBuilder in project zype-android by zype.

the class SettingsProvider method isLogined.

public boolean isLogined() {
    // Check if Access Token needs to be refreshed
    if (isAccessTokenExpiring() == true) {
        WebApiManager webApiManager = WebApiManager.getInstance();
        AuthParamsBuilder builder = new AuthParamsBuilder();
        builder.addClientId();
        builder.addClientSecret();
        builder.addRefreshToken(SettingsProvider.getInstance().getRefreshToken());
        builder.addGrandType("refresh_token");
        webApiManager.executeRequest(WebApiManager.Request.AUTH_REFRESH_ACCESS_TOKEN, builder.build());
    }
    return !TextUtils.isEmpty(getAccessToken()) && !TextUtils.isEmpty(getRefreshToken()) && !TextUtils.isEmpty(getScope()) && !TextUtils.isEmpty(getTokenType()) && getExpiresIn() != -1L;
}
Also used : AuthParamsBuilder(com.zype.android.webapi.builder.AuthParamsBuilder) WebApiManager(com.zype.android.webapi.WebApiManager)

Example 2 with AuthParamsBuilder

use of com.zype.android.webapi.builder.AuthParamsBuilder in project zype-android by zype.

the class LoginActivity method attemptLogin.

public void attemptLogin() {
    hideKeyboard();
    String email = emailWrapper.getEditText().getText().toString();
    String password = passwordWrapper.getEditText().getText().toString();
    if (BuildConfig.DEBUG) {
        if (email.length() == 0 && password.length() == 0) {
            email = "brian@zypemedia.com";
            password = "Password1";
        }
    }
    if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
        passwordWrapper.setError(getString(R.string.error_invalid_password));
    }
    if (TextUtils.isEmpty(email)) {
        emailWrapper.setError(getString(R.string.error_field_required));
    } else if (!isEmailValid(email)) {
        emailWrapper.setError(getString(R.string.error_invalid_email));
    } else {
        emailWrapper.setErrorEnabled(false);
        passwordWrapper.setErrorEnabled(false);
        showProgress(true);
        AuthParamsBuilder builder = new AuthParamsBuilder();
        builder.addUsername(email);
        builder.addPassword(password);
        builder.addClientId();
        builder.addClientSecret();
        builder.addGrandType("password");
        getApi().executeRequest(WebApiManager.Request.AUTH_RETRIEVE_ACCESS_TOKEN, builder.build());
    }
}
Also used : AuthParamsBuilder(com.zype.android.webapi.builder.AuthParamsBuilder)

Example 3 with AuthParamsBuilder

use of com.zype.android.webapi.builder.AuthParamsBuilder in project zype-android by zype.

the class LoginActivity method handleRetrieveAccessToken.

@Subscribe
public void handleRetrieveAccessToken(RetrieveAccessTokenEvent event) {
    RetrieveAccessToken.RetrieveAccessTokenData data = event.getEventData().getModelData();
    SettingsProvider.getInstance().saveAccessToken(data.getAccessToken());
    SettingsProvider.getInstance().saveExpiresIn(data.getExpiresIn());
    SettingsProvider.getInstance().saveRefreshToken(data.getRefreshToken());
    SettingsProvider.getInstance().saveScope(data.getScope());
    SettingsProvider.getInstance().saveTokenType(data.getTokenType());
    Logger.d("handleRetrieveAccessToken");
    AuthParamsBuilder authParamsBuilder = new AuthParamsBuilder();
    authParamsBuilder.addToken(data.getAccessToken());
    getApi().executeRequest(WebApiManager.Request.TOKEN_INFO, authParamsBuilder.build());
}
Also used : RetrieveAccessToken(com.zype.android.webapi.model.auth.RetrieveAccessToken) AuthParamsBuilder(com.zype.android.webapi.builder.AuthParamsBuilder) Subscribe(com.squareup.otto.Subscribe)

Aggregations

AuthParamsBuilder (com.zype.android.webapi.builder.AuthParamsBuilder)3 Subscribe (com.squareup.otto.Subscribe)1 WebApiManager (com.zype.android.webapi.WebApiManager)1 RetrieveAccessToken (com.zype.android.webapi.model.auth.RetrieveAccessToken)1