if (ret == null) {
final long issuedAt = System.currentTimeMillis();
final String contentType = response.getHeader("Content-Type");
final String responseString = response.getResponseAsString();
final OAuth2Message msg = this.oauth2MessageProvider.get();
if (contentType.startsWith("text/plain")) {
// Facebook does this
msg.parseQuery('?' + responseString);
} else if (contentType.startsWith("application/json")) {
// Google does this
final JSONObject responseJson = new JSONObject(responseString);
msg.parseJSON(responseJson.toString());
} else {
if (isLogging) {
TokenAuthorizationResponseHandler.LOG.log("Unhandled Content-Type {0}", contentType);
TokenAuthorizationResponseHandler.LOG.exiting(
TokenAuthorizationResponseHandler.LOG_CLASS, "handleResponse", null);
}
ret = TokenAuthorizationResponseHandler.getError("Unhandled Content-Type "
+ contentType);
}
final OAuth2Error error = msg.getError();
if (error != null) {
ret = getError("error parsing request", null, msg.getErrorUri(),
msg.getErrorDescription());
} else if (error == null && accessor != null) {
final String accessToken = msg.getAccessToken();
final String refreshToken = msg.getRefreshToken();
final String expiresIn = msg.getExpiresIn();
final String tokenType = msg.getTokenType();
final String providerName = accessor.getServiceName();
final String gadgetUri = accessor.getGadgetUri();
final String scope = accessor.getScope();
final String user = accessor.getUser();
final String macAlgorithm = msg.getMacAlgorithm();
final String macSecret = msg.getMacSecret();
final Map<String, String> unparsedProperties = msg.getUnparsedProperties();
if (accessToken != null) {
final OAuth2Token storedAccessToken = this.store.createToken();
storedAccessToken.setIssuedAt(issuedAt);
if (expiresIn != null) {