npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libsaml

v1.0.0

Published

Parse SAML2 attributes into a JavaScript object.

Downloads

1,150

Readme

libsaml Build Status

Parses SAML responses into JS objects you can read and manipulate.

Install

$ yarn add https://github.com/bgshacklett/libsaml.git
$ npm install git+https://github.com/bgshacklett/libsaml.git --save

Usage

LibSaml was designed for use in any Node.js environment whether that's a web app or a standalone script.

const express = require('express');
const LibSaml = require('libsaml');
const app     = express();

app.post('/saml/callback/?', function(req, res, next){
  var parser = new LibSaml(res.body.SAMLResponse);
  res.json(parser.toObject());
});

app.listen(3000);

Methods

Constructor

To instantiate a new SAML parser:

const LibSaml = require('libsaml');

const parser = new LibSaml(SAMLResponse);

After passing your SAML response as a string to the constructor you now have access to the following methods.

toObject()

Returns the parsed SAML as a JavaScript object.

var parsedObject = parser.toObject();

toJSON()

Returns parsed SAML as a JSON string. Once you've instantiated the module and passed it raw SAML you can get its value as a JSON string with parser.toJSON().

getAttribute()

Returns an array containing the value(s) of any SAML attribute(s) by name. The name you pass to this function should be the same as what the attribute value in your SAML is. For example, given this SAML:

<saml2:Attribute Name="First Name">
  <saml2:AttributeValue>John</saml2:AttributeValue>
</saml2:Attribute>

To get the value of First Name you would call it like this:

// assuming you've instantiated the library as `parser` with
// `new LibSaml(SAMLResponse)`...
var firstName = parser.get('first name');
console.log(firstName[0]); //=> 'John'

You don't need to worry about case sensitivity. Internally the case of the string you pass is normalized so when it is compared against the parsed SAML it will automagically match the name of the key as its stored internally if it exists.

parse()

This is a private method. It is called internally when you pass your SAML to the constructor. You should never need to call this manually. See the source code if you want to know more about it.

Testing

Testing requires Mocha and Unexpected. Both will be installed with your preferred package manager.

  1. Clone the repository
  2. Run yarn install (or npm install)
  3. Finally, run yarn test or npm test

Contributing

Contributions are welcome. Pull requests without corresponding tests will not be merged outside of exceptional circumstances.

Credit

This is a fork of saml2js by Bill Patrianakos, which is, in turn, a fork of saml2json by John Flesch. Thanks for your original work!