Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use in-app browser to authorize an account.

  • Loading branch information...
commit a935d450abd7d62faf923849050bfce453695761 1 parent 5e741ed
@yllus authored
View
1  callback.html
@@ -0,0 +1 @@
+Please wait, saving authorization to use Twitter...
View
1  config.xml
@@ -11,4 +11,5 @@
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
+ <feature id="blackberry.polarmobile.childbrowser" />
</widget>
View
26 data/account_settings_notsetup.html
@@ -1,26 +0,0 @@
-<p>
- A Twitter account has not been set up for use with Lemma. To set up an account, follow the instructions found below:
- <ol>
- <li>
- Click the <b>Launch Browser</b> button found below to launch a browser session.<br />
- <uibutton class="qnx" style="width: 200px; margin-top: 10px;" onclick="doAuthGetPIN();">
- <label>Launch Browser</label>
- </uibutton>
- </li>
- <li style="margin-top: 20px;">Log in to your Twitter account and authorize the Lemma application.</li>
- <li style="margin-top: 20px;">
- Make note of the PIN code displayed and enter it below.
- <div style="margin: 10px 0 0 5px; height: 50px; width: 600px;">
- <div style="float: left;">
- <input id="accessPIN" class="qnx" type="text" />
- </div>
- <div style="float: left;">
- <uibutton class="qnx" style="width: 125px;" onclick="doAuthStepTwo();">
- <label>Authorize!</label>
- </uibutton>
- </div>
- </div>
- </li>
- <li style="margin-top: 20px;">Start using Lemma!</li>
- </ol>
-</p>
View
25 js/lemma.js
@@ -5,7 +5,13 @@ var status_autorefresh = 0;
var just_launched = 1;
var last_view_type = 0;
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.
var accountIsSet = null;
@@ -88,11 +94,18 @@ String.prototype.replace_smart_quotes = function() {
// Makes use of jsOAuth ( https://github.com/bytespider/jsOAuth ).
// To simulate in Chrome: chrome.exe --disable-web-security
function doAuthGetPIN() {
- oauth.post('https://twitter.com/oauth/request_token',
+ oauth.post('https://api.twitter.com/oauth/request_token',
{},
function(data) {
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);
+ }
}
);
}
@@ -100,10 +113,8 @@ function doAuthGetPIN() {
// 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 ).
// To simulate in Chrome: chrome.exe --disable-web-security
-function doAuthStepTwo() {
- var accountPIN = $('#accessPIN').value;
-
- oauth.get('https://twitter.com/oauth/access_token?oauth_verifier=' + accountPIN + '&' + requestParams,
+function doAuthStepTwo( oauth_verifier ) {
+ oauth.get('https://twitter.com/oauth/access_token?oauth_verifier=' + oauth_verifier + '&' + requestParams,
function(data) {
// Split the query string as needed.
var accessParams = {};
View
28 js/navigation.js
@@ -434,4 +434,30 @@ function viewAbout() {
function doAutoRefresh() {
eval(last_view_action);
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];
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.