-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Netflix OAuth Module #25
Open
slickplaid
wants to merge
9
commits into
bnoguchi:master
Choose a base branch
from
slickplaid:netflix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d9a455
Make .authorizePath() accept either URI or path
2af742e
Removed function execution.
3ea658b
Added netflix module
326fca9
Merge branch 'master' into netflix
49249f6
Added netflix to README.md
40c7f76
Added example for netflix module.
52824c6
Removed some rogue debug comments and vanity change to README.md
3806fff
merged master
eb9216f
Merged master and merged conflicted lib/modules/oauth.js
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var oauthModule = require('./oauth') | ||
, querystring = require('querystring') | ||
, xml2js = require('xml2js'); | ||
|
||
var netflix = module.exports = | ||
oauthModule.submodule('netflix') | ||
.apiHost('http://api.netflix.com') | ||
.oauthHost('http://api.netflix.com') | ||
|
||
// abnormal authorize URI | ||
.authorizePath('https://api-user.netflix.com/oauth/login') | ||
|
||
.entryPath('/auth/netflix') | ||
.callbackPath('/auth/netflix/callback') | ||
|
||
.getAccessToken( function (reqToken, reqTokenSecret, verifier) { | ||
var promise = this.Promise() | ||
, extraParams = { | ||
consumer_key: this._consumerKey | ||
, consumer_secret: this._consumerSecret | ||
}; | ||
this.oauth._performSecureRequest(reqToken, reqTokenSecret, "POST", this._apiHost + this._accessTokenPath, extraParams, null, null, function(error,data,res){ | ||
if( error ) promise.fail(error); | ||
else { | ||
var results= querystring.parse( data ); | ||
var oauth_access_token= results["oauth_token"]; | ||
delete results["oauth_token"]; | ||
var oauth_access_token_secret= results["oauth_token_secret"]; | ||
delete results["oauth_token_secret"]; | ||
promise.fulfill(oauth_access_token, oauth_access_token_secret, results) | ||
} | ||
}); | ||
return promise; | ||
}) | ||
|
||
.fetchOAuthUser( function (accessToken, accessTokenSecret, params) { | ||
var promise = this.Promise() | ||
, parser = new xml2js.Parser(); | ||
parser.addListener('end', function(data){ | ||
return promise.fulfill(data); | ||
}); | ||
this.oauth.get(this.apiHost() + '/users/'+params.user_id, accessToken, accessTokenSecret, function (err, data) { | ||
if (err) return promise.fail(err); | ||
return parser.parseString(data); | ||
}); | ||
return promise; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
var everyModule = require('./everymodule') | ||
, OAuth = require('oauth').OAuth | ||
, url = require('url') | ||
, querystring = require('querystring') | ||
, extractHostname = require('../utils').extractHostname; | ||
|
||
var oauth = module.exports = | ||
|
@@ -10,7 +11,8 @@ everyModule.submodule('oauth') | |
, oauthHost: 'the host for the OAuth provider' | ||
, requestTokenPath: "the path on the OAuth provider's domain where we request the request token, e.g., /oauth/request_token" | ||
, accessTokenPath: "the path on the OAuth provider's domain where we request the access token, e.g., /oauth/access_token" | ||
, authorizePath: 'the path on the OAuth provider where you direct a visitor to login, e.g., /oauth/authorize' | ||
, authorizePath: 'the path or full uri on the OAuth provider where you direct a visitor to login, e.g., /oauth/authorize or http://api-user.netflix.com/' | ||
, moreAuthQueryParams: 'Additional querystrings to provide during the authorize step. e.g., { application_name: "testapp" }' | ||
, consumerKey: 'the api key provided by the OAuth provider' | ||
, consumerSecret: 'the api secret provided by the OAuth provider' | ||
, myHostname: 'e.g., http://localhost:3000 . Notice no trailing slash' | ||
|
@@ -81,7 +83,7 @@ everyModule.submodule('oauth') | |
} | ||
|
||
var p = this.Promise(); | ||
this.oauth.getOAuthRequestToken( function (err, token, tokenSecret, authUrl, params) { | ||
this.oauth.getOAuthRequestToken( function (err, token, tokenSecret, /* authUrl, */ params) { | ||
if (err) return p.fail(err); | ||
p.fulfill(token, tokenSecret); | ||
}); | ||
|
@@ -95,12 +97,53 @@ everyModule.submodule('oauth') | |
_provider.tokenSecret = tokenSecret; | ||
}) | ||
.redirectToProviderAuth( function (res, token) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Start of fix for #23 |
||
var url = (/^http/.test(this._authorizePath)) | ||
? this._authorizePath | ||
: this._oauthHost + this._authorizePath | ||
, params = { | ||
oauth_token: token | ||
, oauth_callback: this._myHostname + this._callbackPath | ||
} | ||
, additionalParams = this._moreAuthQueryParams | ||
, param | ||
, authUri; | ||
|
||
if (additionalParams) for (var k in additionalParams) { | ||
param = additionalParams[k]; | ||
// Leaving this in in case needed in the future. | ||
// Caused problems because req object wasn't passed to this function. | ||
//if ('function' === typeof param) { | ||
// // e.g., for facebook module, param could be | ||
// // function () { | ||
// // return this._scope && this.scope(); | ||
// // } | ||
// additionalParams[k] = // cache the function call | ||
// param = param.call(this); | ||
//} | ||
//if ('function' === typeof param) { | ||
// // this.scope() itself could be a function | ||
// // to allow for dynamic scope determination - e.g., | ||
// // function (req, res) { | ||
// // return req.session.onboardingPhase; // => "email" | ||
// // } | ||
// param = param.call(this, req, res); | ||
//} | ||
params[k] = param; | ||
} | ||
|
||
authUri = url + '?' + querystring.stringify(params); | ||
res.writeHead(303, {'Location': authUri}); | ||
res.end(); | ||
|
||
// Build URI from host + authorizePath if authorizeURI is absent (default behavior) | ||
// Note: Not all oauth modules need oauth_callback as a uri query parameter. As far as I know, only readability's | ||
// module needs it as a uri query parameter. However, in cases such as twitter, it allows you to over-ride | ||
// the callback url settings at dev.twitter.com from one place, your app code, rather than in two places -- i.e., | ||
// your app code + dev.twitter.com app settings. | ||
res.writeHead(303, { 'Location': this._oauthHost + this._authorizePath + '?oauth_token=' + token + '&oauth_callback=' + this._myHostname + this._callbackPath }); | ||
res.end(); | ||
//res.writeHead(303, { 'Location': this._oauthHost + this._authorizePath + '?oauth_token=' + token + '&oauth_callback=' + this._myHostname + this._callbackPath }); | ||
//res.end(); | ||
|
||
}) | ||
|
||
// Steps for GET `callbackPath` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the
authUrl
variable is doing here. In the corresponding function, it doesn't have that variable passed to this function. I needed to use the params variable so that's why it's been corrected. I left it in commented just so you can see what I did in case it breaks something for some reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit 7cb7aa078613242d62a3, I have a conflict.
authUrl
variable doesn't seem to be in the parent oauth module. The callback on line 460 ofnode_modules/oauth/lib/oauth.js
iscallback(null, oauth_token, oauth_token_secret, results );
which doesn't includeauthUrl
Just wanted to get your clarification on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that shouldn't be there. I just removed it in a commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the vigilant eyes.