Skip to content

Commit

Permalink
Adding a configuration mechanism (that may not stay) to allow overrid…
Browse files Browse the repository at this point in the history
…ing of the name of the access token used when requesting resources
  • Loading branch information
ciaranj committed Jun 29, 2011
1 parent cb6e4ea commit 5707c48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Change History
==============

* 0.9.2 - Correct content length calculated for non-ascii post bodies (Thanks selead)
Allowed for configuration of the 'access token' name used when requesting protected resources (OAuth2)
* 0.9.1 - Added support for automatically following 302 redirects (Thanks neyric) Added support for OAuth Echo (Thanks Ryan LeFevre). Improved handling of 2xx responses (Thanks Neil Mansilla).
* 0.9.0 - Compatibility fixes to bring node-oauth up to speed with node.js 0.4x [thanks to Rasmus Andersson for starting the work ]
* 0.8.4 - Fixed issue #14 (Parameter ordering ignored encodings). Added support for repeated parameter names. Implements issue #15 (Use native SHA1 if available, 10x speed improvement!). Fixed issue #16 (Should use POST when requesting access tokens.). Fixed Issue #17 (OAuth2 spec compliance). Implemented enhancement #13 (Adds support for PUT & DELETE http verbs). Fixes issue #18 (Complex/Composite url arguments [thanks novemberborn])
Expand Down
16 changes: 12 additions & 4 deletions lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ exports.OAuth2= function(clientId, clientSecret, baseSite, authorizePath, access
this._clientId= clientId;
this._clientSecret= clientSecret;
this._baseSite= baseSite;
this._authorizeUrl= authorizePath || "/oauth/authorize"
this._accessTokenUrl= accessTokenPath || "/oauth/access_token"
this._authorizeUrl= authorizePath || "/oauth/authorize";
this._accessTokenUrl= accessTokenPath || "/oauth/access_token";
this._accessTokenName= "access_token";
}


// This 'hack' method is required for sites that don't use
// 'access_token' as the name of the access token (for requests).
// ( http://tools.ietf.org/html/draft-ietf-oauth-v2-16#section-7 )
// it isn't clear what the correct value should be atm, so allowing
// for specific (temporary?) override for now.
exports.OAuth2.prototype.setAccessTokenName= function ( name ) {
this._accessTokenName= name;
}

exports.OAuth2.prototype._getAccessTokenUrl= function( params ) {
var params= params || {};
Expand Down Expand Up @@ -40,7 +48,7 @@ exports.OAuth2.prototype._request= function(method, url, headers, access_token,
realHeaders['Content-Length']= 0;
if( access_token ) {
if( ! parsedUrl.query ) parsedUrl.query= {};
parsedUrl.query["access_token"]= access_token;
parsedUrl.query[this._accessTokenName]= access_token;
}

var result= "";
Expand Down

0 comments on commit 5707c48

Please sign in to comment.