Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A simple example of PIN-based oauth flow with Twitter and jsOAuth
<!DOCTYPE html>
A simple example of PIN-based oauth flow with Twitter and jsOAuth.
This is mostly based on/copied from <>.
Get jsOAuth at <>
<meta charset="utf-8">
<title>jsOauth test</title>
<script src=""></script>
<script type="text/javascript" src="jsOAuth-1.1.js"></script>
<style type="text/css" media="screen">
$(document).ready(function() {
var options = {
consumerKey: 'YOUR_CONSUMER_KEY',
consumerSecret: 'YOUR_CONSUMER_SECRET'
var requestParams;
var accessParams;
var oauth = OAuth(options);
function(data) {
requestParams = data.text
function(data) { alert('darn'); console.dir(data) }
$('#pinbutton').click(function() {
if ($('#pin').val()) {
function(data) {
// split the query string as needed
var accessParams = {};
var qvars_tmp = data.text.split('&');
for (var i = 0; i < qvars_tmp.length; i++) {;
var y = qvars_tmp[i].split('=');
accessParams[y[0]] = decodeURIComponent(y[1]);
oauth.setAccessToken([accessParams.oauth_token, accessParams.oauth_token_secret]);
function(data) { alert('poop'); console.dir(data); }
function getHomeTimeline() {
function(data) {
entries = JSON.parse(data.text);
var html = [];
for (var i = 0; i < entries.length; i++) {
function(data) { alert('lame'); console.dir(data); }
<h1>jsOauth test</h1>
When you get a PIN, enter it here.
<input id="pin" type="text" value=""><button id='pinbutton'>Save</button>
<div id="timeline">
rxgx commented May 20, 2011

This won't work with a normal AJAX call (because of Access-Control-Allow-Origin) and requires JSONP.


Yes, this will only work in platforms not bound by same-origin, such as Titanium Desktop, Adobe AIR and webOS.

How would the implementation using JSONP?


pretty sure Twitter oAuth does not support JSONP responses. YMMV.

Some examples using no-PIN mode ?

I read this article but it seemed very confusing.


Sorry, I'd have to suggest looking at the Twitter docs – I don't have time to write up more examples for you.

No problem, I search the Twitter docs.
Anyway, thanks for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment