Skip to content

Commit

Permalink
Conform to latest conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 16, 2012
1 parent 6302b9e commit f8cf798
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: "node_js"
node_js:
- 0.4
- 0.6
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@
NODE = node
TEST = vows
TEST = ./node_modules/.bin/vows
TESTS ?= test/*-test.js

test:
Expand Down
11 changes: 9 additions & 2 deletions README.md
@@ -1,7 +1,7 @@
# Passport-Instagram

[Passport](https://github.com/jaredhanson/passport) strategy for authenticating
with Instagram using the OAuth 2.0 API.
with [Instagram](http://instagr.am/) using the OAuth 2.0 API.

## Installation

Expand Down Expand Up @@ -50,10 +50,17 @@ application:
res.redirect('/');
});

#### Examples
## Examples

For a complete, working example, refer to the [login example](https://github.com/jaredhanson/passport-instagram/tree/master/examples/login).

## Tests

$ npm install --dev
$ make test

[![Build Status](https://secure.travis-ci.org/jaredhanson/passport-instagram.png)](http://travis-ci.org/jaredhanson/passport-instagram)

## Credits

- [Jared Hanson](http://github.com/jaredhanson)
Expand Down
2 changes: 1 addition & 1 deletion lib/passport-instagram/index.js
Expand Up @@ -7,7 +7,7 @@ var Strategy = require('./strategy');
/**
* Framework version.
*/
exports.version = '0.1.0';
require('pkginfo')(module, 'version');

/**
* Expose constructors.
Expand Down
17 changes: 10 additions & 7 deletions lib/passport-instagram/strategy.js
Expand Up @@ -75,18 +75,21 @@ Strategy.prototype.userProfile = function(accessToken, done) {
// the internal node-oauth module will have to be modified to support
// exposing this information.

this._oauth2.getProtectedResource('https://api.instagram.com/v1/users/self', accessToken, function (err, body, res) {
this._oauth2.get('https://api.instagram.com/v1/users/self', accessToken, function (err, body, res) {
if (err) { return done(err); }

try {
o = JSON.parse(body);
var json = JSON.parse(body);

var profile = { provider: 'instagram' };
profile.id = o.data.id;
profile.displayName = o.data.full_name;
profile.name = { familyName: o.data.last_name,
givenName: o.data.first_name };
profile.username = o.data.username;
profile.id = json.data.id;
profile.displayName = json.data.full_name;
profile.name = { familyName: json.data.last_name,
givenName: json.data.first_name };
profile.username = json.data.username;

profile._raw = body;
profile._json = json;

done(null, profile);
} catch(e) {
Expand Down
20 changes: 17 additions & 3 deletions package.json
Expand Up @@ -2,15 +2,29 @@
"name": "passport-instagram",
"version": "0.1.0",
"description": "Instagram authentication strategy for Passport.",
"author": "Jared Hanson <jaredhanson@gmail.com> (http://www.jaredhanson.net/)",
"author": { "name": "Jared Hanson", "email": "jaredhanson@gmail.com", "url": "http://www.jaredhanson.net/" },
"repository": {
"type": "git",
"url": "http://github.com/jaredhanson/passport-instagram.git"
"url": "git://github.com/jaredhanson/passport-instagram.git"
},
"bugs": {
"url": "http://github.com/jaredhanson/passport-instagram/issues"
},
"main": "./lib/passport-instagram",
"dependencies": {
"passport-oauth": ">= 0.1.0"
"pkginfo": "0.2.x",
"passport-oauth": "0.1.x"
},
"devDependencies": {
"vows": "0.6.x"
},
"scripts": {
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
},
"engines": { "node": ">= 0.4.0" },
"licenses": [ {
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
} ],
"keywords": ["passport", "instagram", "auth", "authn", "authentication", "identity"]
}
10 changes: 8 additions & 2 deletions test/strategy-test.js
Expand Up @@ -29,7 +29,7 @@ vows.describe('InstagramStrategy').addBatch({
function() {});

// mock
strategy._oauth2.getProtectedResource = function(url, accessToken, callback) {
strategy._oauth2.get = function(url, accessToken, callback) {
var body = '{"data": { "id": "1574083", "username": "snoopdogg", "full_name": "Snoop Doggy Dogg", "first_name": "Snoop", "last_name": "Dogg", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg", "bio": "This is my bio", "website": "http://snoopdogg.com", "counts": { "media": 1320, "follows": 420, "followed_by": 3410 } } }';

callback(null, body, undefined);
Expand Down Expand Up @@ -61,6 +61,12 @@ vows.describe('InstagramStrategy').addBatch({
assert.equal(profile.name.familyName, 'Dogg');
assert.equal(profile.name.givenName, 'Snoop');
},
'should set raw property' : function(err, profile) {
assert.isString(profile._raw);
},
'should set json property' : function(err, profile) {
assert.isObject(profile._json);
},
},
},

Expand All @@ -73,7 +79,7 @@ vows.describe('InstagramStrategy').addBatch({
function() {});

// mock
strategy._oauth2.getProtectedResource = function(url, accessToken, callback) {
strategy._oauth2.get = function(url, accessToken, callback) {
callback(new Error('something-went-wrong'));
}

Expand Down

0 comments on commit f8cf798

Please sign in to comment.