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 for authnRequestBinding in SAML options #529

Merged
merged 8 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/passport-saml/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class SAML {
options.RACComparison = 'exact';
}

options.authnRequestBinding = options.authnRequestBinding || 'HTTP-Redirect';

return options as SAMLOptions;
}

Expand Down
4 changes: 1 addition & 3 deletions src/passport-saml/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Strategy extends PassportStrategy {
_verify: VerifyWithRequest | VerifyWithoutRequest;
_saml: saml.SAML;
_passReqToCallback?: boolean;
_authnRequestBinding?: string;

constructor(options: SamlConfig, verify: VerifyWithRequest | VerifyWithoutRequest) {
super();
Expand All @@ -34,7 +33,6 @@ class Strategy extends PassportStrategy {
this._verify = verify;
this._saml = new saml.SAML(options);
this._passReqToCallback = !!options.passReqToCallback;
this._authnRequestBinding = options.authnRequestBinding || 'HTTP-Redirect';
}

authenticate(req: RequestWithUser, options: AuthenticateOptions & AuthorizeOptions): void {
Expand Down Expand Up @@ -92,7 +90,7 @@ class Strategy extends PassportStrategy {
} else {
const requestHandler = {
'login-request': () => {
if (this._authnRequestBinding === 'HTTP-POST') {
if (this._saml.options.authnRequestBinding === 'HTTP-POST') {
this._saml.getAuthorizeForm(req, (err: Error | null, data?: any) => {
if (err) {
this.error(err);
Expand Down
2 changes: 1 addition & 1 deletion src/passport-saml/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface SAMLOptions {
authnContext: string | string[];
forceAuthn: boolean;
skipRequestCompression: boolean;
authnRequestBinding?: string;
RACComparison: 'exact' | 'minimum' | 'maximum' | 'better';
providerName: string;
passive: boolean;
Expand Down Expand Up @@ -65,7 +66,6 @@ export type SamlConfig = Partial<SAMLOptions> & StrategyOptions
interface StrategyOptions {
name?: string;
passReqToCallback?: boolean;
authnRequestBinding?: string;
}

export interface SamlScopingConfig {
Expand Down
8 changes: 2 additions & 6 deletions test/multiSamlStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ describe('strategy#authenticate', function() {
it('passes options on to saml strategy', function(done) {
var passportOptions = {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
getSamlOptions: function (req, fn) {
try {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
} catch (err2) {
done(err2);
Expand All @@ -71,6 +69,7 @@ describe('strategy#authenticate', function() {
var superAuthenticateStub = this.superAuthenticateStub;
var samlOptions = {
issuer: 'http://foo.issuer',
authnRequestBinding: 'HTTP-POST',
callbackUrl: 'http://foo.callback',
cert: 'deadbeef',
host: 'lvh',
Expand Down Expand Up @@ -133,12 +132,10 @@ describe('strategy#logout', function() {
it('passes options on to saml strategy', function(done) {
var passportOptions = {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
getSamlOptions: function (req, fn) {
try {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
} catch (err2) {
done(err2);
Expand All @@ -154,6 +151,7 @@ describe('strategy#logout', function() {
var superLogoutMock = this.superLogoutMock;
var samlOptions = {
issuer: 'http://foo.issuer',
authnRequestBinding: 'HTTP-POST',
cjbarth marked this conversation as resolved.
Show resolved Hide resolved
callbackUrl: 'http://foo.callback',
cert: 'deadbeef',
host: 'lvh',
Expand Down Expand Up @@ -218,12 +216,10 @@ describe('strategy#generateServiceProviderMetadata', function() {
it('passes options on to saml strategy', function(done) {
var passportOptions = {
passReqToCallback: true,
authnRequestBinding: 'HTTP-POST',
cjbarth marked this conversation as resolved.
Show resolved Hide resolved
getSamlOptions: function (req, fn) {
try {
fn();
strategy._passReqToCallback.should.eql(true);
strategy._authnRequestBinding.should.eql('HTTP-POST');
done();
} catch (err2) {
done(err2);
Expand Down