Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Boilerplate for xAuth

bytespider edited this page Mar 1, 2012 · 1 revision

Gist

    var oauth = OAuth({
        consumerKey: 'MY-CONSUMER-KEY',
        consumerSecret: 'MY-CONSUMER-SECRET'
    });

    oauth.post('https://api.twitter.com/oauth/access_token', {
        'x_auth_username': 'DarthVader',
        'x_auth_password': 'Luk3i5myS0n',
        'x_auth_mode': 'client_auth'
    }, successCallback, failureCallback);

    function successCallback(response)
    {
        // contain within is a token of joy
        var token = oauth.parseTokenRequest(response.text);

        var tokenKey = token.oauth_token;
        var tokenSecret = token.oauth_token_secret;

        oauth.setAccessToken(tokenKey, tokenSecret);

        // launch the rest of my application
        app.nowHasTokenCode();
    }

    function failureCallback(response)
    {
        console.error('Something bad happened', response.text);
    }
Clone this wiki locally