use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.
the class ZypeAuthentication method saveAccessToken.
public static void saveAccessToken(Map<String, Object> data) {
String accessToken = ((AccessTokenResponse) data.get(RESPONSE_ACCESS_TOKEN)).getAccessToken();
String refreshToken = ((AccessTokenResponse) data.get(RESPONSE_ACCESS_TOKEN)).getRefreshToken();
long createdAt = 0;
long expiresIn = 0;
String resourceOwnerId = "";
if (data.get(RESPONSE_ACCESS_TOKEN_INFO) != null) {
createdAt = ((AccessTokenInfoResponse) data.get(RESPONSE_ACCESS_TOKEN_INFO)).createdAt;
expiresIn = ((AccessTokenInfoResponse) data.get(RESPONSE_ACCESS_TOKEN_INFO)).expiresInSeconds;
resourceOwnerId = ((AccessTokenInfoResponse) data.get(RESPONSE_ACCESS_TOKEN_INFO)).resourceOwnerId;
}
ConsumerData consumer = null;
if (data.get(RESPONSE_CONSUMER) != null) {
consumer = ((ConsumerResponse) data.get(RESPONSE_CONSUMER)).consumerData;
}
boolean isDeviceLinked = (Boolean) data.get(RESPONSE_IS_DEVICE_LINKED);
if (com.amazon.android.module.BuildConfig.DEBUG) {
Log.d(TAG, "Storing access token: " + accessToken);
}
Preferences.setString(IAuthentication.ACCESS_TOKEN, accessToken);
Preferences.setLong(ZypeAuthentication.PREFERENCE_ACCESS_TOKEN_CREATED_AT, createdAt);
Preferences.setLong(ZypeAuthentication.PREFERENCE_ACCESS_TOKEN_EXPIRES_IN, expiresIn);
Preferences.setString(ZypeAuthentication.PREFERENCE_REFRESH_TOKEN, refreshToken);
Preferences.setString(ZypeAuthentication.PREFERENCE_RESOURCE_OWNER_ID, resourceOwnerId);
Preferences.setLong(ZypeAuthentication.PREFERENCE_CONSUMER_SUBSCRIPTION_COUNT, consumer.subscriptionCount);
Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_EMAIL, consumer.email);
Preferences.setString(ZypeAuthentication.PREFERENCE_CONSUMER_ID, consumer.id);
Preferences.setBoolean(ZypeAuthentication.PREFERENCE_IS_DEVICE_LINKED, isDeviceLinked);
}
use of com.zype.fire.api.Model.AccessTokenResponse 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;
}
use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.
the class ZypeApi method retrieveAccessTokenWithPin.
public AccessTokenResponse retrieveAccessTokenWithPin(String deviceId, String pin) {
Map<String, String> params = new HashMap<>();
params.put(LINKED_DEVICE_ID, deviceId);
params.put(PIN, pin);
params.put(CLIENT_ID, ZypeSettings.CLIENT_ID);
params.put(CLIENT_GRANT_TYPE, "password");
try {
Response response = apiImpl.retrieveAccessToken(params).execute();
if (response.isSuccessful()) {
return (AccessTokenResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.
the class ZypeApi method refreshAccessToken.
public AccessTokenResponse refreshAccessToken(String refreshToken) {
Map<String, String> params = new HashMap<>();
params.put(REFRESH_TOKEN, refreshToken);
params.put(CLIENT_ID, ZypeSettings.CLIENT_ID);
params.put(CLIENT_GRANT_TYPE, "refresh_token");
try {
Response response = apiImpl.retrieveAccessToken(params).execute();
if (response.isSuccessful()) {
return (AccessTokenResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of com.zype.fire.api.Model.AccessTokenResponse in project zype-firebuilder by zype.
the class ZypeApi method retrieveAccessToken.
/*
* OAuth
*/
public AccessTokenResponse retrieveAccessToken(String username, String password) {
Map<String, String> params = new HashMap<>();
params.put(USERNAME, username);
params.put(PASSWORD, password);
params.put(CLIENT_ID, ZypeSettings.CLIENT_ID);
params.put(CLIENT_GRANT_TYPE, "password");
try {
Response response = apiImpl.retrieveAccessToken(params).execute();
if (response.isSuccessful()) {
return (AccessTokenResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Aggregations