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 (isLogging) {
TokenAuthorizationResponseHandler.LOG.log("Content-Type {0}", contentType);
TokenAuthorizationResponseHandler.LOG.log("Response String {0}", responseString);
}
if (contentType.startsWith("application/json")) {
// Google does this
final JSONObject responseJson = new JSONObject(responseString);
msg.parseJSON(responseJson.toString());
} else {
// Default assume it is application/x-www-form-urlencoded
// Facebook has a content type of text/plain
// GitHub has a content type of application/x-www-form-urlencoded
msg.parseQuery('?' + responseString);
}
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) {