Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ accepts these credentials and calls `done` providing a user, as well as
}
));

#### Sign Requests

If you enabled "Enforce Signed Requests" in the Instagram Client settings
(Under Security Tab) set `signRequests = true` in the `options` object
when configuring the strategy.

#### Authenticate Requests

Use `passport.authenticate()`, specifying the `'instagram'` strategy, to
Expand Down
23 changes: 19 additions & 4 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* Module dependencies.
*/
var util = require('util')
, OAuth2Strategy = require('passport-oauth2')
, InternalOAuthError = require('passport-oauth2').InternalOAuthError;
, crypto = require('crypto')
, OAuth2Strategy = require('passport-oauth2')
, InternalOAuthError = require('passport-oauth2').InternalOAuthError;


/**
Expand Down Expand Up @@ -47,6 +48,8 @@ function Strategy(options, verify) {

OAuth2Strategy.call(this, options, verify);
this.name = 'instagram';
this._clientSecret = options.clientSecret;
this._signRequests = options.signRequests;
}

/**
Expand Down Expand Up @@ -75,8 +78,20 @@ Strategy.prototype.userProfile = function(accessToken, done) {
// would avoid the need for an extra request during this step. However,
// the internal node-oauth module will have to be modified to support
// exposing this information.

this._oauth2.get('https://api.instagram.com/v1/users/self', accessToken, function (err, body, res) {

var baseInstagramAPI = 'https://api.instagram.com/v1'
, userInfoEndpoint = '/users/self';

if (this._signRequests) {
// Sign user profile info request according to Instagram API
// This is required if "Force Signed Requests" is enabled in Instaram client's settongs (Under Security)
// https://www.instagram.com/developer/secure-api-requests/
var toSign = userInfoEndpoint + '|access_token=' + accessToken;
var sig = crypto.createHmac('sha256', this._clientSecret).update(toSign).digest('hex');
userInfoEndpoint += '?sig=' + sig;
}

this._oauth2.get(baseInstagramAPI + userInfoEndpoint, accessToken, function (err, body, res) {
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }

try {
Expand Down