Skip to content

Commit

Permalink
Use in-app browser to authorize an account.
Browse files Browse the repository at this point in the history
  • Loading branch information
yllus committed Oct 8, 2011
1 parent 5e741ed commit a935d45
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 34 deletions.
1 change: 1 addition & 0 deletions callback.html
@@ -0,0 +1 @@
Please wait, saving authorization to use Twitter...
1 change: 1 addition & 0 deletions config.xml
Expand Up @@ -11,4 +11,5 @@
<feature id="blackberry.invoke" /> <feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" /> <feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" /> <feature id="blackberry.identity" />
<feature id="blackberry.polarmobile.childbrowser" />
</widget> </widget>
26 changes: 0 additions & 26 deletions data/account_settings_notsetup.html

This file was deleted.

25 changes: 18 additions & 7 deletions js/lemma.js
Expand Up @@ -5,7 +5,13 @@ var status_autorefresh = 0;
var just_launched = 1; var just_launched = 1;
var last_view_type = 0; var last_view_type = 0;
var last_view_action = 'doRefresh();'; var last_view_action = 'doRefresh();';
var timer_autorefresh; var timer_autorefresh, timer_oauth;

// Browser variables.
var browser = null;
if (typeof blackberry !== 'undefined') {
browser = blackberry.polarmobile.childbrowser;
}


// Account variables. // Account variables.
var accountIsSet = null; var accountIsSet = null;
Expand Down Expand Up @@ -88,22 +94,27 @@ String.prototype.replace_smart_quotes = function() {
// Makes use of jsOAuth ( https://github.com/bytespider/jsOAuth ). // Makes use of jsOAuth ( https://github.com/bytespider/jsOAuth ).
// To simulate in Chrome: chrome.exe --disable-web-security // To simulate in Chrome: chrome.exe --disable-web-security
function doAuthGetPIN() { function doAuthGetPIN() {
oauth.post('https://twitter.com/oauth/request_token', oauth.post('https://api.twitter.com/oauth/request_token',
{}, {},
function(data) { function(data) {
requestParams = data.text; requestParams = data.text;
followLink('https://twitter.com/oauth/authorize?' + data.text);
if (typeof blackberry !== 'undefined') {
browser.loadURL('https://api.twitter.com/oauth/authorize?' + data.text);
timer_oauth = setTimeout('doAutoAuthCheck();', 5000);
}
else {
followLink('https://api.twitter.com/oauth/authorize?' + data.text);
}
} }
); );
} }


// Authorization step #2: Submit the PIN and get back an access token and access token secret. // Authorization step #2: Submit the PIN and get back an access token and access token secret.
// Makes use of jsOAuth ( https://github.com/bytespider/jsOAuth ). // Makes use of jsOAuth ( https://github.com/bytespider/jsOAuth ).
// To simulate in Chrome: chrome.exe --disable-web-security // To simulate in Chrome: chrome.exe --disable-web-security
function doAuthStepTwo() { function doAuthStepTwo( oauth_verifier ) {
var accountPIN = $('#accessPIN').value; oauth.get('https://twitter.com/oauth/access_token?oauth_verifier=' + oauth_verifier + '&' + requestParams,

oauth.get('https://twitter.com/oauth/access_token?oauth_verifier=' + accountPIN + '&' + requestParams,
function(data) { function(data) {
// Split the query string as needed. // Split the query string as needed.
var accessParams = {}; var accessParams = {};
Expand Down
28 changes: 27 additions & 1 deletion js/navigation.js
Expand Up @@ -434,4 +434,30 @@ function viewAbout() {
function doAutoRefresh() { function doAutoRefresh() {
eval(last_view_action); eval(last_view_action);
timer_autorefresh = setTimeout('doAutoRefresh();', status_autorefresh); timer_autorefresh = setTimeout('doAutoRefresh();', status_autorefresh);
} }

function doAutoAuthCheck() {
var str_currlocation = browser.getLocation();
if ( str_currlocation.indexOf(options['callbackUrl'], 0) >= 0 ) {
var oauth_verifier = getQueryVariable(str_currlocation, 'oauth_verifier');

// Close the in-app browser.
browser.close();

doAuthStepTwo(oauth_verifier);
}
else {
timer_autorefresh = setTimeout('doAutoAuthCheck();', 5000);
}
}

function getQueryVariable(url, variable) {
var query = url.substring((url.indexOf('?') + 1), url.length);
var vars = query.split('&');
for ( var i = 0; i < vars.length; i++ ) {
var pair = vars[i].split('=');
if (pair[0] == variable) {
return pair[1];
}
}
}

0 comments on commit a935d45

Please sign in to comment.