Skip to content
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

Alter OAuth2 so that you can specify the redirectPath in the url #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/modules/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ everyModule.submodule('oauth2')
.accepts('session auth')
.promises(null)
.step('sendResponse')
.accepts('res')
.accepts('res session')
.promises(null)

.stepseq('authCallbackErrorSteps')
Expand All @@ -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
Expand All @@ -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});
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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});
Expand Down