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

Allow returnURL to be function #3

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 6 additions & 5 deletions lib/passport-openid/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var passport = require('@passport-next/passport-strategy')
*
* Options:
* - `returnURL` URL to which the OpenID provider will redirect the user after authentication
* May be given as a function which will get the req object as an argument.
* - `realm` the part of URL-space for which an OpenID authentication request is valid
* - `profile` enable profile exchange, defaults to _false_
* - `pape` when present, enables the OpenID Provider Authentication Policy Extension
Expand Down Expand Up @@ -136,9 +137,9 @@ function Strategy(options, verify) {
var oauth = new openid.OAuthHybrid(oauthOptions);
extensions.push(oauth);
}
this._relyingParty = new openid.RelyingParty(
options.returnURL,

this._relyingParty = req => new openid.RelyingParty(
options.returnURL instanceof Function ? options.returnURL(req) : options.returnURL,
options.realm,
(options.stateless === undefined) ? false : options.stateless,
(options.secure === undefined) ? true : options.secure,
Expand Down Expand Up @@ -180,7 +181,7 @@ Strategy.prototype.authenticate = function(req) {
if (req.query['openid.mode'] === 'cancel') { return this.fail({ message: 'OpenID authentication canceled' }); }

var self = this;
this._relyingParty.verifyAssertion(req.url, function(err, result) {
this._relyingParty(req).verifyAssertion(req.url, function(err, result) {
if (err) { return self.error(new InternalOpenIDError('Failed to verify assertion', err)); }
if (!result.authenticated) { return self.error(new Error('OpenID authentication failed')); }

Expand Down Expand Up @@ -245,7 +246,7 @@ Strategy.prototype.authenticate = function(req) {
if (!identifier) { return this.fail(new BadRequestError('Missing OpenID identifier')); }

var self = this;
this._relyingParty.authenticate(identifier, false, function(err, providerUrl) {
this._relyingParty(req).authenticate(identifier, false, function(err, providerUrl) {
if (err || !providerUrl) { return self.error(new InternalOpenIDError('Failed to discover OP endpoint URL', err)); }
self.redirect(providerUrl);
});
Expand Down