0

Learning about OAuth, I came across a big question. How to call a JavaScript function in the callback url with jsOAuth?

When you click Connect to twitter, the login screen opens, then the Twitter authorize APP and after he simply calls the callback URL. I would like to close this window and call a JavaScript function on the page that originated.

See my tests

Code

oauth = OAuth({
            consumerKey: srv.key,
            consumerSecret: srv.secret,
            requestTokenUrl: srv.request_token,
            authorizationUrl: srv.authorize,
            accessTokenUrl: srv.access_token,
            callbackUrl: "http://ridermansb.kodingen.com/twitter.html"
        });

Screenshots

I took some Screenshots will explain better:

Authorize

after

Callback

I asked this same question on GitHub;

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ridermansb
  • 10,779
  • 24
  • 115
  • 226

1 Answers1

0

What about :

oauth = OAuth({
        consumerKey: srv.key,
        consumerSecret: srv.secret,
        requestTokenUrl: srv.request_token,
        authorizationUrl: srv.authorize,
        accessTokenUrl: srv.access_token,
        callbackUrl: "http://ridermansb.kodingen.com/callback.html"
    });

and in callback.html

<html>
<head>
<script type="text/javascript">
/**
 * call parent window function and close
 */
function callback() {
    window.opener.functionName(querystring('token'));
    window.close();
}
</script>
</head>
<body onload="callback()">
</body>
</html>

To be tested.

ebtokyo
  • 2,369
  • 4
  • 23
  • 33