Skip to content

Instantly share code, notes, and snippets.

@timanrebel
Created November 22, 2013 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timanrebel/7596146 to your computer and use it in GitHub Desktop.
Save timanrebel/7596146 to your computer and use it in GitHub Desktop.
Doing reverse Oauth with Ti.Social
// First do reverse Auth call
var Social = require('dk.napp.social');
var oauthString = '';
var jsOAuth = require('jsOAuth').OAuth;
var oauth = jsOAuth({
consumerKey: 'xxx',
consumerSecret: 'yyy'
});
oauth.request({
method: 'POST',
url: 'https://api.twitter.com/oauth/request_token',
data: {
x_auth_mode: 'reverse_auth'
},
header: {},
success: function(event) {
oauthString = event.text;
if(Social.isRequestTwitterSupported()) { //min iOS6 required
var onSuccess = function(evt) {
Social.removeEventListener("twitterRequest", onSuccess);
Social.removeEventListener("error", onError);
var queryString = {};
evt.response.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { queryString[$1] = $3; }
);
Ti.API.info(queryString);
var tokens = {
access_token: queryString['oauth_token'],
access_token_secret: queryString['oauth_token_secret'],
};
successCallback(tokens);
};
var onError = function(e) {
Social.removeEventListener("twitterRequest", onSuccess);
Social.removeEventListener("error", onError);
if(e.status == 'No account')
e.status = 'No Twitter account has been added in iOS';
errorCallback(e.status);
};
Social.addEventListener("twitterRequest", onSuccess);
Social.addEventListener("error", onError);
// Request Reverse Auth call
Social.requestTwitter({
requestType: 'POST',
url: 'https://api.twitter.com/oauth/access_token'
}, {
x_reverse_auth_target: 'xxx',
x_reverse_auth_parameters: oauthString
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment