Reviewers: etnu00, shindig.remailer_gmail.com,
http://codereview.appspot.com/63214/diff/1/4
File features/src/main/javascript/features/core.io/io.js (right):
http://codereview.appspot.com/63214/diff/1/4#newcode367
Line 367: if (window.oauthReceivedCallbackUrl_) {
Because I'm trying to make this work automatically even for gadgets that
don't use the popup library. If we can do that, we don't need to ask
gadget authors to change their gadgets to support 1.0a.
I'm not particular about window vs gadgets vs gadgets.io, the main thing
is that OAuth gadgets today don't actually require gadgets.oauth.Popup
in order to work.
The main reason to prefer window over gadgets.io is that osapi.oauth
might make gadgets.io obsolete.
Please review this at http://codereview.appspot.com/63214
Affected files:
M features/src/main/javascript/features/core.io/io.js
M features/src/main/javascript/features/oauthpopup/oauthpopup.js
M features/src/test/javascript/features/core.io/iotest.js
M
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/OAuthCallbackServlet.java
Index:
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/OAuthCallbackServlet.java
===================================================================
---
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/OAuthCallbackServlet.java
(revision 782883)
+++
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/OAuthCallbackServlet.java
(working copy)
@@ -70,10 +70,7 @@
"<body>\n" +
"<script type='text/javascript'>\n" +
"try {\n" +
- " if (window.opener && window.opener.gadgets &&
window.opener.gadgets.oauth\n" +
- " && window.opener.gadgets.oauth.Popup) {\n" +
- "
window.opener.gadgets.oauth.Popup.setReceivedCallbackUrl(document.location.href);\n"
+
- " }\n" +
+ " window.opener.oauthReceivedCallbackUrl_ =
document.location.href;\n" +
"} catch (e) {\n" +
"}\n" +
"window.close();\n" +
Index: features/src/test/javascript/features/core.io/iotest.js
===================================================================
--- features/src/test/javascript/features/core.io/iotest.js (revision
782883)
+++ features/src/test/javascript/features/core.io/iotest.js (working copy)
@@ -529,6 +529,7 @@
this.assertEquals("http://sp.example.com/authz?oauth_token=foo",
resp.oauthApprovalUrl);
+ window.oauthReceivedCallbackUrl_ = "http://shindig?oauth_verifier=12345";
var req = new fakeXhr.Expectation("POST", "http://example.com/json");
this.setStandardArgs(req, true);
req.setBodyArg("url", "http://target.example.com/somepage");
@@ -536,6 +537,8 @@
req.setBodyArg("st", "authtoken");
req.setBodyArg("oauthState", "newState");
req.setBodyArg("refresh", null);
+ req.setBodyArg("OAUTH_RECEIVED_CALLBACK",
+ "http://shindig?oauth_verifier=12345");
req.setHeader("Content-Type", "application/x-www-form-urlencoded");
var resp = this.makeFakeResponse(
@@ -553,6 +556,7 @@
},
params);
this.assertEquals("personal data", resp.text);
+ this.assertEquals(undefined, window.oauthReceivedCallbackUrl_);
};
IoTest.prototype.testSignedEquivalentToOAuth = function() {
Index: features/src/main/javascript/features/core.io/io.js
===================================================================
--- features/src/main/javascript/features/core.io/io.js (revision 782883)
+++ features/src/main/javascript/features/core.io/io.js (working copy)
@@ -364,12 +364,9 @@
// OAuth goodies
if (auth === "oauth" || auth === "signed") {
- if (gadgets.oauth && gadgets.oauth.Popup &&
gadgets.oauth.Popup.getReceivedCallbackUrl) {
- var callbackResponse =
gadgets.oauth.Popup.getReceivedCallbackUrl();
- if (callbackResponse) {
- paramData.OAUTH_RECEIVED_CALLBACK = callbackResponse;
- gadgets.oauth.Popup.setReceivedCallbackUrl(null);
- }
+ if (window.oauthReceivedCallbackUrl_) {
+ paramData.OAUTH_RECEIVED_CALLBACK =
window.oauthReceivedCallbackUrl_;
+ window.oauthReceivedCallbackUrl_ = undefined;
}
paramData.oauthState = oauthState || "";
// Just copy the OAuth parameters into the req to the server
Index: features/src/main/javascript/features/oauthpopup/oauthpopup.js
===================================================================
--- features/src/main/javascript/features/oauthpopup/oauthpopup.js
(revision 782883)
+++ features/src/main/javascript/features/oauthpopup/oauthpopup.js (working
copy)
@@ -200,11 +200,3 @@
self.handleApproval_();
};
};
-
-gadgets.oauth.Popup.setReceivedCallbackUrl = function(url) {
- gadgets.oauth.Popup.receivedCallbackUrl_ = url;
-};
-
-gadgets.oauth.Popup.getReceivedCallbackUrl = function() {
- return gadgets.oauth.Popup.receivedCallbackUrl_;
-};