Skip to content

Commit

Permalink
Enable dynamic callback url
Browse files Browse the repository at this point in the history
  • Loading branch information
dpuscher committed Jan 23, 2020
1 parent 21b8ec4 commit df42b15
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/lastfm_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function LastfmStrategy(options, verify){
options = options || {};
if (!options.api_key && !options.clientID) { throw new TypeError('LastfmStrategy requires a clientID obtained from http://www.last.fm/api/account/create'); }
if (!options.secret && !options.clientSecret) { throw new TypeError('LastfmStrategy requires a clientSecret obtained from http://www.last.fm/api/account/create'); }
if (!options.callback_url && !options.callbackURL) { throw new TypeError('LastfmStrategy requires a callbackURL option'); }

if (!verify || typeof(verify) != 'function') { throw new TypeError('LastfmStrategy requires verify callback function'); }

Expand All @@ -37,7 +36,11 @@ function LastfmStrategy(options, verify){

LastfmStrategy.prototype.authenticate = function(request, options){
var self = this;
var authUrl = self.getAuthenticationUrl({cb:self.callbackURL});
var callbackURL = options.callback_url || options.callbackURL || self.callbackURL;

if (!callbackURL) throw new TypeError('LastfmStrategy requires a callbackURL option');

var authUrl = self.getAuthenticationUrl({cb:callbackURL});


if (request.query && request.query.token){
Expand Down Expand Up @@ -80,7 +83,7 @@ LastfmStrategy.prototype.getAuthenticationUrl = function(param) {

if (params.token) { urlParts.query.token = params.token; }

var rtn = `${url.format(urlParts)}&cb=${this.callbackURL}`;
var rtn = `${url.format(urlParts)}&cb=${param.cb}`;
return rtn ;
};

Expand Down

0 comments on commit df42b15

Please sign in to comment.