fixing oauth problems with redirection for the Freebase API

git-svn-id: http://google-refine.googlecode.com/svn/trunk@2516 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2012-08-01 21:46:53 +00:00
parent 4cfb921082
commit 2cb31b8b29
6 changed files with 67 additions and 13 deletions

View File

@ -42,7 +42,7 @@ FreebaseLoadingDialog.prototype._createDialog = function() {
this._elmts = DOM.bind(dialog);
this._elmts.cancelButton.click(function() { self._dismiss(); });
var provider = "www.freebase.com";
var provider = "freebase.com";
var authorization = this._elmts.authorization;
var loadButton = this._elmts.loadButton;

View File

@ -52,19 +52,23 @@ public class FreebaseProvider extends Provider {
@Override
public String getRequestTokenServiceURL() {
return "https://" + host + "/api/oauth/request_token";
return "https://api." + host + "/api/oauth/request_token";
}
@Override
public String getAccessTokenServiceURL() {
return "https://" + host + "/api/oauth/access_token";
return "https://api." + host + "/api/oauth/access_token";
}
@Override
public String getUserAuthorizationURL() {
return "https://" + host + "/signin/app";
return "https://www." + host + "/signin/app";
}
@Override
public String getRealm() {
return "http://api" + host + "/";
}
@Override
public OAuthConsumer createConsumer(String consumerKey, String consumerSecret) {

View File

@ -71,7 +71,7 @@ public class FreebaseUtils {
static final Logger logger = LoggerFactory.getLogger("freebase");
static final public String FREEBASE_HOST = "www.freebase.com";
static final public String FREEBASE_HOST = "freebase.com";
static final private String FREEQ_URL = "http://data.labs.freebase.com/freeq/refine";
@ -81,15 +81,15 @@ public class FreebaseUtils {
static final private int JUDGES = 4;
private static String getUserInfoURL(String host) {
return "http://" + host + "/api/service/user_info";
return "http://api." + host + "/api/service/user_info";
}
private static String getMQLWriteURL(String host) {
return "http://" + host + "/api/service/mqlwrite";
return "http://api." + host + "/api/service/mqlwrite";
}
private static String getMQLReadURL(String host) {
return "http://" + host + "/api/service/mqlread";
return "http://api." + host + "/api/service/mqlread";
}
private static String getUserAgent() {

View File

@ -0,0 +1,50 @@
package com.google.refine.oauth;
import java.util.Iterator;
import oauth.signpost.OAuth;
import oauth.signpost.http.HttpParameters;
import oauth.signpost.http.HttpRequest;
import oauth.signpost.signature.SigningStrategy;
public class AuthorizationHeaderSigningStrategy implements SigningStrategy {
private static final long serialVersionUID = 1L;
private final String realm;
public AuthorizationHeaderSigningStrategy(String realm) {
this.realm = realm;
}
public String writeSignature(String signature, HttpRequest request, HttpParameters requestParameters) {
StringBuilder sb = new StringBuilder();
sb.append("OAuth ");
if (realm != null) {
sb.append("realm=\"" + realm + "\", ");
}
// add all (x_)oauth parameters
HttpParameters oauthParams = requestParameters.getOAuthParameters();
oauthParams.put(OAuth.OAUTH_SIGNATURE, signature, true);
Iterator<String> iter = oauthParams.keySet().iterator();
while (iter.hasNext()) {
String key = iter.next();
sb.append(oauthParams.getAsHeaderElement(key));
if (iter.hasNext()) {
sb.append(", ");
}
}
String header = sb.toString();
OAuth.debugOut("Auth Header", header);
request.setHeader(OAuth.HTTP_AUTHORIZATION_HEADER, header);
return header;
}
}

View File

@ -41,7 +41,6 @@ import javax.servlet.http.HttpServletRequest;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
import oauth.signpost.http.HttpParameters;
public class OAuthUtilities {
@ -77,9 +76,7 @@ public class OAuthUtilities {
throw new RuntimeException("Can't find secrets for provider '" + provider.getHost() + "'");
}
OAuthConsumer oauthConsumer = provider.createConsumer(consumer_info[0],consumer_info[1]);
HttpParameters params = new HttpParameters();
params.put("realm", provider.getHost());
oauthConsumer.setAdditionalParameters(params);
oauthConsumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy(provider.getRealm()));
return oauthConsumer;
}

View File

@ -36,7 +36,6 @@ package com.google.refine.oauth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
public abstract class Provider {
protected String host;
@ -51,6 +50,10 @@ public abstract class Provider {
public String getHost() {
return host;
}
public String getRealm() {
return "http://" + host + "/";
}
abstract public String getRequestTokenServiceURL();
abstract public String getAccessTokenServiceURL();