}
public static ClientAccessToken fromMapToClientToken(Map<String, String> map) {
if (map.containsKey(OAuthConstants.ACCESS_TOKEN)
&& map.containsKey(OAuthConstants.ACCESS_TOKEN_TYPE)) {
ClientAccessToken token = new ClientAccessToken(
map.remove(OAuthConstants.ACCESS_TOKEN_TYPE),
map.remove(OAuthConstants.ACCESS_TOKEN));
String refreshToken = map.remove(OAuthConstants.REFRESH_TOKEN);
if (refreshToken != null) {
token.setRefreshToken(refreshToken);
}
String expiresInStr = map.remove(OAuthConstants.ACCESS_TOKEN_EXPIRES_IN);
if (expiresInStr != null) {
token.setExpiresIn(Long.valueOf(expiresInStr));
}
String issuedAtStr = map.remove(OAuthConstants.ACCESS_TOKEN_ISSUED_AT);
token.setIssuedAt(issuedAtStr != null ? Long.valueOf(issuedAtStr)
: System.currentTimeMillis() / 1000);
String scope = map.remove(OAuthConstants.SCOPE);
if (scope != null) {
token.setApprovedScope(scope);
}
token.setParameters(map);
return token;
} else {
return null;
}
}