Adding a configuration mechanism (that may not stay) to allow overriding of the name of the access token used when requesting resources

This commit is contained in:
ciaranj
2011-06-30 00:03:22 +01:00
parent cb6e4ea3b8
commit 5707c480df
2 changed files with 13 additions and 4 deletions

View File

@ -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 || {};
@ -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= "";