GithubHelp home page GithubHelp logo

krakenjs / passport-saml-encrypted Goto Github PK

View Code? Open in Web Editor NEW
14.0 12.0 26.0 47 KB

A strategy for Passport authentication that supports encrypted SAML responses

License: MIT License

JavaScript 100.00%

passport-saml-encrypted's Introduction

NOTE Not under active developement, but I will accept PR's


passport-saml-encrypted

A strategy for Passport authentication that supports encrypted SAML responses.

This is largely a fork of https://github.com/bergie/passport-saml Which seems to be dormant.

It was created to support encrypted SAML responses.

Returned data object:

Note: If there is a single value for an attribute, it will be a string. If there are multiple values, it will be an array. E.G.:

{ issuer: 'https://fedpocv1.corp.company.com',
  nameID: 'g2IpU4vJ53211ila09gh8wUtzgm',
  nameIDFormat: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
  Email: ' [email protected]',
  Corpid: 'lmarkus',
  FirstName: 'Lenny',
  LastName: 'Markus',
  ROLE_NAME: [ 'R_DEFAULT_ADMINISTRATION_ROLE', 'V_V_OPERATIONS' ] }

###Custom Request Builder Callbacks Sometimes you need specific parameters and attributes for your authorization and logout requests. Using the following configuration keys, you can supply a function that returns a string that is the request xml. The params function parameter to the callback contains:

  • id - A unique id created for this request
  • instant - The instant time for this request
  • req - The request object.
  • options - The options you passed to SamlStrategy

An example follows:

fnAuthRequest = function(params) {
  return "<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\"" + params.id 
    + "\" Version=\"2.0\" IssueInstant=\"" + params.instant 
    + "\" ProtocolBinding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" Destination=\"" 
    + params.options.entryPoint + "\">" + "<saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" 
    + params.options.issuer + "</saml:Issuer>\n</samlp:AuthnRequest>\n";
}

fnLogoutRequest = function(params) {
  return "<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" "
    + "xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"" + params.id + "\" Version=\"2.0\" IssueInstant=\""
    + params.instant + "\" Destination=\"" + params.options.entryPoint + "\">"
    + "<saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">" + params.options.issuer + "</saml:Issuer>"
    + "<saml:NameID Format=\"" + params.req.user.nameIDFormat + "\">" + params.req.user.nameID + "</saml:NameID>"
    + "</samlp:LogoutRequest>";
}
passport.use(new SamlStrategy(
  {
    path: '/login/callback',
    entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
    issuer: 'passport-saml'
    customBuildAuthorizeRequestCallback:fnAuthRequest
    customBuildLogoutRequestCallback:fnLogoutRequest
  }, fnSamlDone)

Contributions welcome.

Documentation from the original forked repo follows:

Passport-SAML

This is a SAML 2.0 authentication provider for Passport, the Node.js authentication library.

The code was originally based on Michael Bosworth's express-saml library.

Passport-SAML has been tested to work with both SimpleSAMLphp based Identity Providers, and with Active Directory Federation Services.

Installation

$ npm install passport-saml-encrypted

Usage

Configure strategy

This example utilizes the Feide OpenIdp identity provider. You need an account there to log in with this. You also need to register your site as a service provider.

The SAML identity provider will redirect you to the URL provided by the path configuration.

passport.use(new SamlStrategy(
  {
    path: '/login/callback',
    entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
    issuer: 'passport-saml'
  },
  function(profile, done) {
    findByEmail(profile.email, function(err, user) {
      if (err) {
        return done(err);
      }
      return done(null, user);
    });
  })
));

Provide the authentication callback

You need to provide a route corresponding to the path configuration parameter given to the strategy:

app.post('/login/callback',
  passport.authenticate('saml', { failureRedirect: '/', failureFlash: true }),
  function(req, res) {
    res.redirect('/');
  }
);

Authenticate requests

Use passport.authenticate(), specifying saml as the strategy:

app.get('/login',
  passport.authenticate('saml', { failureRedirect: '/', failureFlash: true }),
  function(req, res) {
    res.redirect('/');
  }
);

Security and signatures

Passport-SAML uses the HTTP Redirect Binding for its AuthnRequests, and expects to receive the messages back via the HTTP POST binding.

Authentication requests sent by Passport-SAML can be signed using RSA-SHA1. To sign them you need to provide a private key in the PEM format via the privateCert configuration key. For example:

    privateCert: fs.readFileSync('./cert.pem', 'utf-8')

It is a good idea to validate the incoming SAML Responses. For this, you can provide the Identity Provider's certificate using the cert confguration key:

    cert: 'MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W=='

If the response is encrypted, you need to supply your public key to the SAML provider, and use your private key to decrypt the response. This is specified as:

    privateCert: fs.readFileSync('path/to/privkey.pem', 'utf-8')

Usage with Active Directory Federation Services

Here is a configuration that has been proven to work with ADFS:

  {
    entryPoint: 'https://ad.example.net/adfs/ls/',
    issuer: 'https://your-app.example.net/login/callback',
    callbackUrl: 'https://your-app.example.net/login/callback',
    cert: 'MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W==',
    privateCert: fs.readFileSync('./ssl/privkey.pem', 'utf-8'),  //need to generate key using openssl and put it in server
    encryptedSAML:true,
    identifierFormat:"urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
  }

Please note that ADFS needs to have a trust established to your service in order for this to work.

passport-saml-encrypted's People

Contributors

coffutt avatar jashman avatar kprakasam avatar markstos avatar maxmil7 avatar shaunwarman avatar sumeetkakkar avatar tdub7229 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

passport-saml-encrypted's Issues

How To Singout Idp

Hi, could you show me an example about how to signout the idp。
while i found “Strategy.prototype.logout” in Strategy,but there is no readme about how to use it。
THX

Remove Signature element from the xml before verifying it

in the saml.js file you can see this code

sig.loadSignature(signature.toString());
return sig.checkSignature(xml);

if the signature element was not removed from the assertion the digest value will be different.
so the correct code will be

sig.loadSignature(signature.toString());
//remove the signature element
doc.removeChild(signature);
return sig.checkSignature(doc.toString());

Please add Try-Catch over xml-cypto methods

Please add try-catch blocks wherever functions from xml-crypto modules are used . This is because xml-crypto in itself doesnt seem to handle exceptions well.

Sample Stack trace due to this :

at Object.findAttr (/apps/snap/snapnodeweb/node_modules/xml-crypto/lib/utils.js:20:18) at SignedXml.loadReference (/apps/snap/snapnodeweb/node_modules/xml-crypto/lib/signed-xml.js:320:29) at SignedXml.loadSignature (/apps/snap/snapnodeweb/node_modules/xml-crypto/lib/signed-xml.js:280:10) at SAML.validateSignature (/apps/snap/snapnodeweb/node_modules/passport-saml-encrypted/lib/saml.js:236:7) at SAML.validateResponse (/apps/snap/snapnodeweb/node_modules/passport-saml-encrypted/lib/saml.js:258:33) at Strategy.authenticate (/apps/snap/snapnodeweb/node_modules/passport-saml-encrypted/lib/strategy.js:31:16) at attempt (/apps/snap/snapnodeweb/node_modules/passport/lib/middleware/authenticate.js:343:16) at authenticate (/apps/snap/snapnodeweb/node_modules/passport/lib/middleware/authenticate.js:344:7) at Layer.handle [as handle_request] (/apps/snap/snapnodeweb/node_modules/express/lib/router/layer.js:95:5) at next (/apps/snap/snapnodeweb/node_modules/express/lib/router/route.js:131:13) at Route.dispatch (/apps/snap/snapnodeweb/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/apps/snap/snapnodeweb/node_modules/express/lib/router/layer.js:95:5) at /apps/snap/snapnodeweb/node_modules/express/lib/router/index.js:277:22 at Function.process_params (/apps/snap/snapnodeweb/node_modules/express/lib/router/index.js:330:12) at next (/apps/snap/snapnodeweb/node_modules/express/lib/router/index.js:271:10) at ssoAuthenticate (/apps/snap/snapnodeweb/node_modules/sso-paypal/lib/middleware.js:15:13)

Does this set NSID in cookie?

Hey, we got some inci where the application are using nsid in cookie. though it is generating new every session but the old one is still staying good.
verrsion 0.0.1 just want to understand is this module sets cooki values?

passport dependency with passport-saml dependency

Trying to use passport 0.3.0

Getting error: TypeError: Cannot set property 'user' of undefined [TypeError: Cannot set property 'user' of undefined] TypeError: Cannot set property 'user' of undefined
at /project/node_modules/passport-saml-encrypted/node_modules/passport/lib/http/request.js:50:35

Seem's to be need same fix as fixed on node-saml/passport-saml@010f2d4

public key to verify SAML response

Hi

I'm receiving signed SAML which I have to validate with the public key.

is it something that passport-saml-encrypted can help me with or I have to use passport-saml?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.