samljs

0.1.1 • Public • Published

SAML

This a node.js saml library.

Currently, the library just for SAML 2.0 and SP(Service Provider).

Install

npm install samljs --save

Usage

Use this library to generate SAMLRequest and parse SAMLResponse

SAMLRequest

To generate a SAML AuthNRequest:

const saml = require('samljs');
const AuthnRequest = saml.AuthnRequest;
 
const opts = {
    issuer: 'https://sp.example.com',
    acs: 'https://sp.example.com/sso/callback',
    ssoService: 'https://idp.example.com/login/sso'
};
const authnReq = new AuthnRequest(opts);
// generate base64 encoded SAMLRequest
var samlRequest1 = authnReq.toEncodedString();
// generate compressed base64 encoded SAMLRequest
var samlRequest2 = authnReq.toCompressedEncodedString();

SAMLResponse

To parse a SAMLResponse

const saml = require('samljs');
 
// the SAMLResponse body from HTTP Request body, such as express's req.body
const body = req.body.SAMLResponse;
 
saml.parseResponse(body, (err, resp) => {
    if (err) {
        // parse failed!
        console.log(err);
        return;
    }
 
    const attributes = resp.getAttributes();
    console.log(attributes);
});

License

BSD-2-Clause License

Readme

Keywords

Package Sidebar

Install

npm i samljs

Weekly Downloads

2

Version

0.1.1

License

BSD-2-Clause

Last publish

Collaborators

  • dmdgeeker