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

fh-wfm-user

v0.6.8

Published

A user module for WFM

Downloads

131

Readme

FeedHenry RainCatcher user Build Status Coverage Status

A module for FeedHenry RainCatcher that manages users, groups and memberships. It provides :

  • Backend services to handle CRUD operations for user, group and membership.
  • Frontend directives and services providing CRUD clients for user, group and membership.

Upgrading to 0.2.0 from 0.1.x

Version 0.2.0 introduces session storage for authenticated users utilizing either MongoDB or Redis as storage engines.

This involves an extra parameter to the initialization of the router for the authentication service which contains the configuration for the session storage.

How to upgrade

In the MBaaS service that authenticates users (e.g. raincatcher-demo-auth), initialize the MBaaS router with the new parameter for supplying the configuration for the session storage.

See the Setup router for Cloud App section for more details.

Version 0.2.1 introduced encryption of the users profile data in localstorage (fh.wfm.profileData). The user will likely need to clear the app data/cache in their phones system settings for this feature to work, as previous plaintext profile data may be left on the phone causing an error when trying to decrypt it. To clear the app data on Android:

  • Step 1: Head to the Settings menu. This can be done by tapping the cog icon in your notification shade.
  • Step 2: Find Apps (or Applications, depending on your device) in the menu, then locate the app that you want to clear the cache or data for.
  • Step 3: Tap on Storage and the buttons for clearing the cache and app data will become available.

Upgrading to 0.1.0 from 0.0.x

Version 0.1.0 introduces secure authentication along with password hashing. Password update for users is available as part of the updated raincatcher-demo-portal (available in Workers > Worker details > Edit)

How to upgrade

Update your mobile application, portal application, cloud application and auth service to utilize version 0.1.x of fh-wfm-user. Update your auth service to reflect changes in raincatcher-demo-auth

You will also need to hash your users' passwords using the new hashing algorithm, utilizing one of the following options:

  • Manually editing the users' passwords through the updated portal app
  • If you already have user passwords stored in a custom persistent storage implementation, run a single-pass migration to store them as hashed strings instead. See this example.

Client-side usage

Config

var mediator = require('fh-wfm-mediator');

var config = {
    //Defaults to true
    forceSessionVerificationOnResume: true
};

userCore(mediator, config);

forceSessionVerificationOnResume

Flag for verifying a session when an app has resumed. This is useful for cases where the app was in the background for an extended period and a check needs to be made to verify that the current session is still valid.

If you have a custom method for verification when the app resumes, set the flag to false.

Subscribed Topics

Users

| Topic | Parameters | | ------------- |:-------------: | | wfm:sync:users:create | {userToCreate: {<user fields>}} | | wfm:sync:users:update | {userToUpdate: {id: "IDOFUSERTOUPDATE", ...}} | | wfm:sync:users:list | NONE | | wfm:sync:users:remove | {userToRemove: {id: "IDOFUSERTOREMOVE"}} | | wfm:sync:users:read | {id: "IDOFUSERTOREAD"} | | wfm:sync:users:read_profile | NONE | | wfm:sync:users:clear_session | NONE | | wfm:sync:users:verify_session | NONE | | wfm:sync:users:has_session | NONE | | wfm:sync:users:authenticate | {username: "user1234", password: "password1234"} |

Usage in an express backend and mbaas service

Setup router for Cloud App

The server-side component of this RainCatcher module exports a function that takes an Express application and mediator instances as parameters, as follows:

var express = require('express')
  , app = express()
  , mbaasExpress = mbaasApi.mbaasExpress()
  , mediator = require('fh-wfm-mediator/lib/mediator')
  ;
// Set authServiceGuid
var authServiceGuid = process.env.WFM_AUTH_GUID;

// configure the express app
...

// setup the wfm user router
require('fh-wfm-user/lib/cloud')(mediator, app, authServiceGuid);

Securing endpoints with the validateSession middleware

Version 0.2.0 of this module adds session storage and management, with the capability of requiring users to be authenticated in order to access certain endpoints of your Cloud App

In order to enforce authentication on specific endpoints for your Cloud App, add the validateSesssion middleware to the middleware chain before the handlers for the endpoints you wish to secure:

var fhMbaasApi = require('fh-mbaas-api');
var validateSession = require('fh-wfm-user/lib/middleware/validateSession');

// in this example, require users to be authenticated for fh-wfm-sync calls
app.use('mbaas/sync', validateSession(mediator, mbaasApi,
  // The last parameter is an array of sub-paths to exclude from session validation
  ['/authpolicy']
));

Retrieving user id for session

Top level applications can now obtain userId for sessionToken. Instead of sending user id from client, current logged user id can be now obtained from session token. See example bellow:

var mbaasApi = require('fh-mbaas-api');
var userSessionApi = require("fh-wfm-user/lib/cloud/sessionApi")(mbaasApi);
  
return userSessionApi.getUserIdForSessionPromise(filter.sessionToken).then(function(userId){
  console.log("userId", userId);
});

Setup MBaaS authentication service

var express = require('express')
  , app = express()
  , mbaasExpress = mbaasApi.mbaasExpress()
  , mediator = require('fh-wfm-mediator/lib/mediator')
  ;
// Set authServiveGuid
var authServiceGuid = process.env.WFM_AUTH_GUID;

// configure the express app
...

// setup the wfm user router
const userRouter = require('fh-wfm-user/lib/router/mbaas');

userRouter.init(
  mediator, // fh-wfm-mediator instance
  expressApp, // express application upon which to mount the router
  ['password'], // userProfileExclusionList - the list of fields from a Users profile to exclude from the HTTP responses

  // Session storage configuration, new in 0.2.0
  {
    store: 'mongo', // The store to utilize for session storage,
                    // current available values are ['mongo', 'redis']
    config: {
      // the following parameters are forwarded to express-session
      secret: 'raincatcher',
      resave: false,
      saveUninitialized: true,
      cookie: {
        secure: true,
        httpOnly: true,
        path: '/'
      }
      // `url` is used by the 'mongo' store for configuration
      url: 'mongodb://localhost:27017/raincatcher-demo-auth-session-store'
      // 'host' and 'port' are used by the 'redis' store
      host: '127.0.0.1',
      port: '6379'
    }
  },

  function callback(err) {
    // router initialized
  });

Note: Setting the userProfileExclusionList array as ['password', 'banner'] will prevent these fields from appearing in the authentication response. By default, the password field is removed from the response. To allow all fields to be sent, set userProfileExclusionList to an empty array.

For a more complete example check the example initialization on raincatcher-demo-auth.

Environment variables

The WFM_AUTH_POLICY_ID env var can be set in the WFM Cloud App to override the default wfm auth policy ID.

Exposed CRUD endpoints

Base url : /api/wfm/[group|user|membership|

| resource | method | returns | | -------- | ------ | ------- | | / | GET | array of users/groups/memberships | | /:id | GET | user/group/membership | | /:id | PUT | updated user/group/membership | | / | POST | created user/group/membership | | /:id | DELETE | deleted user/group/membership |

Exposed Auth endpoints

Base url : /api/wfm/user

| resource | parameters | method | returns | description | | -------- | ------ | ------- | ---- | | /auth | all | {status: 'ok', userId: username, sessionToken: sessiontoken, authResponse: authResponse} | sessionToken : identifier for a specific user for the duration of that user's visit. authResponse : authentication response containing the authenticated users details. | | /verifysession | all | {isValid: true} | | | /revokesession | all | {} | | |

message data structure example

  • user :

  {
    "id" : "156340",
    "username" : "trever",
    "name" : "Trever Smith",
    "position" : "Senior Truck Driver",
    "phone" : "(265) 725 8272",
    "email" : "[email protected]",
    "notes" : "Trever doesn't work during the weekends.",
    "avatar" : "https://s3.amazonaws.com/uifaces/faces/twitter/kolage/128.jpg",
    "banner" : "http://web18.streamhoster.com/pentonmedia/beefmagazine.com/TreverStockyards_38371.jpg"
  }
  • group :
  {
    id: 1010,
    name: 'Drivers',
    role: 'worker'
  }
  • membership :
  {
    id: 0,
    group: 1010,
    user: 156340
  }