Search in sources :

Example 1 with AccessTokenInfoResponse

use of com.zype.fire.api.Model.AccessTokenInfoResponse in project zype-firebuilder by zype.

the class ZypeAuthentication method getAccessTokenWithPin.

public static Map<String, Object> getAccessTokenWithPin(String deviceId, String pin) {
    AccessTokenResponse responseAccessToken = ZypeApi.getInstance().retrieveAccessTokenWithPin(deviceId, pin);
    AccessTokenInfoResponse responseAccessTokenInfo = null;
    ConsumerResponse responseConsumer = null;
    if (responseAccessToken != null) {
        responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
        if (responseAccessTokenInfo != null) {
            responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
        }
    } else {
        return null;
    }
    Map<String, Object> result = new HashMap<>();
    result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
    result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
    result.put(RESPONSE_CONSUMER, responseConsumer);
    result.put(RESPONSE_IS_DEVICE_LINKED, true);
    return result;
}
Also used : HashMap(java.util.HashMap) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Example 2 with AccessTokenInfoResponse

use of com.zype.fire.api.Model.AccessTokenInfoResponse in project zype-firebuilder by zype.

the class ZypeAuthentication method refreshToken.

private Map<String, Object> refreshToken(ResponseHandler responseHandler) {
    AccessTokenResponse responseAccessToken = ZypeApi.getInstance().refreshAccessToken(Preferences.getString(PREFERENCE_REFRESH_TOKEN));
    AccessTokenInfoResponse responseAccessTokenInfo = null;
    ConsumerResponse responseConsumer = null;
    if (responseAccessToken != null) {
        responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
        if (responseAccessTokenInfo != null) {
            responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
        }
    } else {
        return null;
    }
    Map<String, Object> result = new HashMap<>();
    result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
    result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
    result.put(RESPONSE_CONSUMER, responseConsumer);
    result.put(RESPONSE_IS_DEVICE_LINKED, Preferences.getBoolean(PREFERENCE_IS_DEVICE_LINKED));
    return result;
}
Also used : HashMap(java.util.HashMap) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Example 3 with AccessTokenInfoResponse

use of com.zype.fire.api.Model.AccessTokenInfoResponse in project zype-firebuilder by zype.

the class ZypeAuthentication method getAccessToken.

public static Map<String, Object> getAccessToken(String username, String password) {
    // Save user name and password for re-login
    // TODO: Save encoded password
    Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_EMAIL, username);
    Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_PASSWORD, password);
    AccessTokenResponse responseAccessToken = ZypeApi.getInstance().retrieveAccessToken(username, password);
    AccessTokenInfoResponse responseAccessTokenInfo = null;
    ConsumerResponse responseConsumer = null;
    if (responseAccessToken != null) {
        responseAccessTokenInfo = ZypeApi.getInstance().getAccessTokenInfo(responseAccessToken.getAccessToken());
        if (responseAccessTokenInfo != null) {
            responseConsumer = ZypeApi.getInstance().getConsumer(responseAccessTokenInfo.resourceOwnerId, responseAccessToken.getAccessToken());
        }
    } else {
        return null;
    }
    Map<String, Object> result = new HashMap<>();
    result.put(RESPONSE_ACCESS_TOKEN, responseAccessToken);
    result.put(RESPONSE_ACCESS_TOKEN_INFO, responseAccessTokenInfo);
    result.put(RESPONSE_CONSUMER, responseConsumer);
    result.put(RESPONSE_IS_DEVICE_LINKED, false);
    return result;
}
Also used : HashMap(java.util.HashMap) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse)

Aggregations

AccessTokenInfoResponse (com.zype.fire.api.Model.AccessTokenInfoResponse)3 AccessTokenResponse (com.zype.fire.api.Model.AccessTokenResponse)3 ConsumerResponse (com.zype.fire.api.Model.ConsumerResponse)3 HashMap (java.util.HashMap)3