diff --git a/lib/modules/oauth2.js b/lib/modules/oauth2.js index b52be4df..ec609b8d 100644 --- a/lib/modules/oauth2.js +++ b/lib/modules/oauth2.js @@ -74,7 +74,7 @@ everyModule.submodule('oauth2') .accepts('session auth') .promises(null) .step('sendResponse') - .accepts('res') + .accepts('res session') .promises(null) .stepseq('authCallbackErrorSteps') @@ -89,13 +89,20 @@ everyModule.submodule('oauth2') if (!this._myHostname || this._alwaysDetectHostname) { this.myHostname(extractHostname(req)); } + + var redirect_path = url.parse(req.url, true).query['redirect_path']; + + if(redirect_path){ + console.log("The Redirect Path has been set to: " + redirect_path); + req.session.redirect_path = redirect_path; + } var params = { client_id: this.appId() , redirect_uri: this.myHostname() + this.callbackPath() } , authPath = this.authPath() - , url = (/^http/.test(authPath)) + , authUrl = (/^http/.test(authPath)) ? authPath : (this.oauthHost() + authPath) , additionalParams = this.moreAuthQueryParams @@ -121,7 +128,7 @@ everyModule.submodule('oauth2') } params[k] = param; } - return url + '?' + querystring.stringify(params); + return authUrl + '?' + querystring.stringify(params); }) .requestAuthUri( function (res, authUri) { res.writeHead(303, {'Location': authUri}); @@ -163,7 +170,7 @@ everyModule.submodule('oauth2') opts.headers || (opts.headers = {}); opts.headers['Content-Length'] = 0; } - delete opts.query.redirect_uri + // delete opts.query.redirect_uri rest[this.accessTokenHttpMethod()](url, opts) .on('success', function (data, res) { if ('string' === typeof data) { @@ -210,8 +217,10 @@ everyModule.submodule('oauth2') mod.accessToken = auth.accessToken; // this._super() ? }) - .sendResponse( function (res) { - var redirectTo = this.redirectPath(); + .sendResponse( function (res, session) { + var redirectTo = session.redirect_path ? session.redirect_path : this.redirectPath(); + //temporary so delete it + delete session.redirect_path; if (!redirectTo) throw new Error('You must configure a redirectPath'); res.writeHead(303, {'Location': redirectTo});