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(log.isLoggable(Level.FINEST)) {
log.logp(Level.FINEST, CLASS, method, "Content-Type {0}", contentType);
log.logp(Level.FINEST, CLASS, method, "Response String {0}", response);
}
if (contentType.startsWith("application/json")) {
// Google does this
msg.parseJSON(responseString);
} else {
// Facebook does this
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) {
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) {