Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Examples #135

Merged
merged 5 commits into from

2 participants

@azat-co

Added examples of OAuth 1.0 and 2.0 in a mocha test formats.

azat-co added some commits
@azat-co azat-co Update Readme.md
added test/example to get bearer/access_token from Twitter using consumer key+secret and OAuth2
c161653
@azat-co azat-co Update Readme.md
changed to user one require 
46e84fa
@azat-co azat-co Update Readme.md 11ed594
@azat-co azat-co Update Readme.md
added OAuth 1.0 example
08569a2
@azat-co azat-co Update Readme.md
quote mismatch
3fc9c63
@ciaranj ciaranj merged commit 3fc9c63 into ciaranj:master
@ciaranj
Owner

Cheers :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2013
  1. @azat-co

    Update Readme.md

    azat-co authored
    added test/example to get bearer/access_token from Twitter using consumer key+secret and OAuth2
  2. @azat-co

    Update Readme.md

    azat-co authored
    changed to user one require 
  3. @azat-co

    Update Readme.md

    azat-co authored
  4. @azat-co

    Update Readme.md

    azat-co authored
    added OAuth 1.0 example
  5. @azat-co

    Update Readme.md

    azat-co authored
    quote mismatch
This page is out of date. Refresh to see the latest.
Showing with 59 additions and 0 deletions.
  1. +59 −0 Readme.md
View
59 Readme.md
@@ -13,6 +13,65 @@ Installation
$ npm install oauth
+Examples
+==========
+
+To run examples/tests insall Mocha `$ npm install -g mocha` and run `$ mocha you-file-name.js`:
+
+## OAuth1.0
+
+```javascript
+describe('OAuth1.0',function(){
+ var OAuth = require('OAuth');
+
+ it('tests trends Twitter API v1.1',function(done){
+ var oauth = new OAuth.OAuth(
+ 'https://api.twitter.com/oauth/request_token',
+ 'https://api.twitter.com/oauth/access_token',
+ 'your application consumer key',
+ 'your application secret',
+ '1.0A',
+ null,
+ 'HMAC-SHA1'
+ );
+ oauth.get(
+ 'https://api.twitter.com/1.1/trends/place.json?id=23424977',
+ 'your user toke for this app', //test user token
+ 'your user secret for this app', //test user secret
+ function (e, data, res){
+ if (e) console.error(e);
+ console.log(require('util').inspect(data));
+ done();
+ });
+ });
+});
+```
+
+## OAuth2.0
+```javascript
+describe('OAuth2',function(){
+ var OAuth = require('OAuth');
+
+ it('gets bearer token', function(done){
+ var OAuth2 = OAuth.OAuth2;
+ var twitterConsumerKey = 'your key';
+ var twitterConsumerSecret = 'your secret';
+ var oauth2 = new OAuth2(server.config.keys.twitter.consumerKey,
+ twitterConsumerSecret,
+ 'https://api.twitter.com/',
+ null,
+ 'oauth2/token',
+ null);
+ oauth2.getOAuthAccessToken(
+ '',
+ {'grant_type':'client_credentials'},
+ function (e, access_token, refresh_token, results){
+ console.log('bearer: ',access_token);
+ done();
+ });
+ });
+```
+
Change History
==============
Something went wrong with that request. Please try again.