diff --git a/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js b/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js index 23438351c..5ade74863 100644 --- a/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js +++ b/extensions/freebase/module/scripts/dialogs/freebase-loading-dialog.js @@ -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; diff --git a/extensions/freebase/src/com/google/refine/freebase/oauth/FreebaseProvider.java b/extensions/freebase/src/com/google/refine/freebase/oauth/FreebaseProvider.java index 994564156..27593d8df 100644 --- a/extensions/freebase/src/com/google/refine/freebase/oauth/FreebaseProvider.java +++ b/extensions/freebase/src/com/google/refine/freebase/oauth/FreebaseProvider.java @@ -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) { diff --git a/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java b/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java index ec9d0c0d8..61b1b91e5 100644 --- a/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java +++ b/extensions/freebase/src/com/google/refine/freebase/util/FreebaseUtils.java @@ -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() { diff --git a/main/src/com/google/refine/oauth/AuthorizationHeaderSigningStrategy.java b/main/src/com/google/refine/oauth/AuthorizationHeaderSigningStrategy.java new file mode 100644 index 000000000..402a45a30 --- /dev/null +++ b/main/src/com/google/refine/oauth/AuthorizationHeaderSigningStrategy.java @@ -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 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; + } + +} diff --git a/main/src/com/google/refine/oauth/OAuthUtilities.java b/main/src/com/google/refine/oauth/OAuthUtilities.java index 7ae64558c..3e6ff4e65 100644 --- a/main/src/com/google/refine/oauth/OAuthUtilities.java +++ b/main/src/com/google/refine/oauth/OAuthUtilities.java @@ -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; } diff --git a/main/src/com/google/refine/oauth/Provider.java b/main/src/com/google/refine/oauth/Provider.java index 1345a6363..fd97f0622 100644 --- a/main/src/com/google/refine/oauth/Provider.java +++ b/main/src/com/google/refine/oauth/Provider.java @@ -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();