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

ws-credentials

v2.2.1

Published

Inner WS credentials service consumer

Downloads

4

Readme

ws-credentials

Inner WS credentials service consumer

IMPORTANT: This version (2.0.0) is a complete refactor. Beware of migration changes if you come from version 1.x

Install

npm install --save ws-credentials

User details

To get the details of a user:

var credentials = require("ws-credentials")("http://yourserver.com/auth");

credentials.details("tsmith").then(function (userDetails) {
	// userDetails is an object, as such:
	// {
	// 	CN: "Tom Smith",
	// 	Description: null,
	// 	DisplayName: "Tom Wilson Smith",
	// 	GivenName: "Tom",
	// 	GroupType: null,
	// 	HomeDirectory: "\\SVRSOME\HOME\tsmith",
	// 	Mail: "[email protected]",
	// 	MailNickname: "tsmith",
	// 	MemberOf: ["PaperCut", "OtherGroup"],
	// 	Name: "Tom Wilson Smith",
	// 	SAMAccountName: "tsmith",
	// 	Surname: "Smith",
	// 	WhenChanged: "6/5/2016 12:00:26 PM",
	// 	WhenCreated: "8/31/2010 5:54:10 PM"
	// }
}).catch(function (err) {
	console.log("Error getting groups", err);
});

In this example, the username is tsmith, and it returns a promise, and if the promise resolves, it gives you an object with the details shown above.

Authentication

Import it and configure to use against your WS URL:

var credentials = require("ws-credentials")("http://yourserver.com/auth"); // The server base URL

credentials.authenticate("tsmith", "password").then(function (userDetails) {
	// If you're here you're OK.
	// userDetails is an object, as such:
	// {
	// 	CN: "Tom Smith",
	// 	Description: null,
	// 	DisplayName: "Tom Wilson Smith",
	// 	GivenName: "Tom",
	// 	GroupType: null,
	// 	HomeDirectory: "\\SVRSOME\HOME\tsmith",
	// 	Mail: "[email protected]",
	// 	MailNickname: "tsmith",
	// 	MemberOf: ["PaperCut", "OtherGroup"],
	// 	Name: "Tom Wilson Smith",
	// 	SAMAccountName: "tsmith",
	// 	Surname: "Smith",
	// 	WhenChanged: "6/5/2016 12:00:26 PM",
	// 	WhenCreated: "8/31/2010 5:54:10 PM",
	//  groups: ["PaperCut", "OtherGroup"]
	// }

	// IMPORTANT NOTE: The "groups" property is an
	// exact copy of "MemberOf".
}).catch(function (err) {
	// If you're here something went wrong, see what:
	console.log(err.message);
});

If the user is authenticated, it works as the function to get the user details.

User groups

You can get the users groups like this:

var credentials = require("ws-credentials")("http://yourserver.com/auth");

credentials.groups("username").then(function (groups) {
	// groups is an array like: ["ADGroup1", "AnotherADGroup"]
}).catch(function (err) {
	console.log("Error getting groups", err);
});

Mocking

You also have a mock for when you're developing:

var user1 = {
	username: "tsmith",
	password: "fakepass",
	groups: ["group1", "group2"],
	details: { ... }
};

var mock = credentials.Mock([user1, user2, ...]);

This function expects an array of users. Each user has the fields username and password to emulate the authentication; groups to use in the groups function, and details to mock the details function result.

HTTPS

When working over SSL, you'll have to pass the URL with the protocol in it, and another parameter with the path of the certificate. If the path with the certificate is not given, it will trust implicitly on the other end.

var credentials = require("ws-credentials")("https://yourserver.com/auth", "/user/home/certificates/SECURE_CERTIFICATE.pem");

credentials.details("tsmith").then(function (userDetails) {
	// userDetails is an object, as such:
	// {
	// 	CN: "Tom Smith",
	// 	Description: null,
	// 	DisplayName: "Tom Wilson Smith",
	// 	GivenName: "Tom",
	// 	GroupType: null,
	// 	HomeDirectory: "\\SVRSOME\HOME\tsmith",
	// 	Mail: "[email protected]",
	// 	MailNickname: "tsmith",
	// 	MemberOf: ["PaperCut", "OtherGroup"],
	// 	Name: "Tom Wilson Smith",
	// 	SAMAccountName: "tsmith",
	// 	Surname: "Smith",
	// 	WhenChanged: "6/5/2016 12:00:26 PM",
	// 	WhenCreated: "8/31/2010 5:54:10 PM"
	// }
}).catch(function (err) {
	console.log("Error getting groups", err);
});

(same case for groups and authentication)