// Parse and verify type
AccessTokenType tokenType = new AccessTokenType(JSONObjectUtils.getString(jsonObject, "token_type"));
if (! tokenType.equals(AccessTokenType.BEARER))
throw new ParseException("Token type must be \"Bearer\"");
// Parse value
String accessTokenValue = JSONObjectUtils.getString(jsonObject, "access_token");
// Parse lifetime
long lifetime = 0;
if (jsonObject.containsKey("expires_in")) {
// Lifetime can be a JSON number or string
if (jsonObject.get("expires_in") instanceof Number) {
lifetime = JSONObjectUtils.getLong(jsonObject, "expires_in");
}
else {
String lifetimeStr = JSONObjectUtils.getString(jsonObject, "expires_in");
try {
lifetime = new Long(lifetimeStr);
} catch (NumberFormatException e) {
throw new ParseException("Invalid \"expires_in\" parameter, must be integer");
}
}
}