7.0.0 • Published 1 year ago

wsfed v7.0.0

Weekly downloads
316
License
MIT
Repository
github
Last release
1 year ago

WS Federation middleware for node.js.

Build Status

Installation

npm install wsfed

Introduction

This Express middleware is meant to generate a valid WSFederation endpoint that talks saml.

The idea is that you will use another mechanism to validate the user first.

The endpoint supports metadata as well in the url /FederationMetadata/2007-06/FederationMetadata.xml.

Usage

Options

NameDescriptionDefault
getPostURLthe function receives 4 parameters from the request (wtrealm, wreply, request, callback). It must return, via the calback, the URL to post the result response toREQUIRED
getUserFromRequestthe function receives one parameter, the request. It must return the user being authenticated, as an object. This object will be passed to the profile mapper to determine attributes of the response.function(req){ return req.user; }
profileMappera ProfileMapper implementation to convert a user profile to claims (PassportProfile)PassportProfileMapper
certThe public key / certificate of the issuer, in PEM format.REQUIRED
keyThe private key of the issuer, used to sign the response, in PEM format.REQUIRED
issuerthe name of the issuer of the response.
audiencethe name of the audience of the response.
lifetimeThe lifetime of the response, in seconds8 hours
signatureAlgorithmsignature algorithm, options: rsa-sha1, rsa-sha256rsa-sha256
digestAlgorithmdigest algorithm, options: sha1, sha256sha256
jwtif true, uses a JWT token for the signed assertion.false
extendJWTAn object that, is passed, contains claims to be added to JWT signed assertion.{}
jwtAlgorithmIf using JWT signed assertion, indicates the algorithm to be appliedRS256
jwtAllowInsecureKeySizesInsecure and not recommended, for backward compatibility ONLY. If true, allows insecure key sizes to be used when signing with JWTfalse
jwtAllowInvalidAsymmetricKeyTypesInsecure and not recommended, for backward compatibility ONLY. If true, allows a mismatch between JWT algorithm and the actual key type provided to sign.false

Add the middleware as follows:

app.get('/wsfed', wsfed.auth({
  issuer:     'the-issuer',
  cert:       fs.readFileSync(path.join(__dirname, 'some-cert.pem')),
  key:        fs.readFileSync(path.join(__dirname, 'some-cert.key')),
  getPostURL: function (wtrealm, wreply, req, callback) {
    return cb( null, 'http://someurl.com')
  }
}));

WsFederation Metadata

wsfed can generate the metadata document for wsfederation as well. Usage as follows:

app.get('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml', wsfed.metadata({
  issuer:   'the-issuer',
  cert:     fs.readFileSync(path.join(__dirname, 'some-cert.pem')),
}));

It also accept two optionals parameters:

  • profileMapper: a class implementing the profile mapper. This is used to render the claims type information (using the metadata property). See PassportProfileMapper for more information.
  • endpointPath: this is the full path in your server to the auth route. By default the metadata handler uses the metadata request route without /FederationMetadata/2007..blabla.

WsFederation Metadata endpoints ADFS1-like

ADFS v1 uses another set of endpoints for the metadata and the thumbprint. If you have to connect an ADFS v1 client you have to do something like this:

app.get('/wsfed/adfs/fs/federationserverservice.asmx',
    wsfed.federationServerService.wsdl);

app.post('/wsfed/adfs/fs/federationserverservice.asmx',
    wsfed.federationServerService.thumbprint({
      pkcs7: yourPkcs7,
      cert:  yourCert
    }));

notice that you need a pkcs7 with the full chain of all certificates. You can generate this with openssl as follows:

openssl crl2pkcs7 -nocrl \
    -certfile your.crt \
    -certfile another-cert-in-the-chain.crt \
    -out contoso1.p7b

JWT

By default the signed assertion is a SAML token, you can use JWT tokens as follows:

app.get('/wsfed', wsfed.auth({
  jwt:        true,
  issuer:     'the-issuer',
  key:        fs.readFileSync(path.join(__dirname, 'some-cert.key')),
  getPostUrl: function (wtrealm, wreply, req, callback) {
                return cb( null, 'http://someurl.com')
              }
}));

Use the option extendJWT to add claims to the resulted token. jwtAlgorithm option allows to customize the algorithm used to sign tokens.

Since version 7.0.0, restrictions apply on the signature of JWT tokens:

  • RSA key size must be 2048 bits or greater. (unless the not recommended and insecure option jwtAllowInsecureKeySizes is used)
  • Asymmetric keys cannot be used to sign HMAC tokens.
  • Key types must be valid for the signing algorithm (unless the not recommended and insecure option jwtAllowInvalidAsymmetricKeyTypes is used)

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

7.0.0

1 year ago

6.1.0

3 years ago

6.0.0

3 years ago

5.0.0

3 years ago

4.0.0

6 years ago

3.3.3

7 years ago

3.3.2

7 years ago

3.3.1

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.4

8 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.2.0

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.5.7

11 years ago

0.5.6

11 years ago

0.5.5

11 years ago

0.5.4

11 years ago

0.5.3

11 years ago

0.5.2

11 years ago

0.5.1

11 years ago

0.5.0

11 years ago

0.4.0

11 years ago

0.3.11

11 years ago

0.3.10

11 years ago

0.3.9

11 years ago

0.3.8

11 years ago

0.3.7

11 years ago

0.3.6

11 years ago

0.3.5

11 years ago

0.3.4

11 years ago

0.3.3

11 years ago

0.3.2

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.2.8

11 years ago

0.2.7

11 years ago

0.2.6

11 years ago

0.2.5

11 years ago

0.2.4

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.1

11 years ago