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

user-auth-jsonrpc

v0.7.1

Published

package to support in the implementation of an user authentication end-point.

Downloads

5

Readme

user-auth-jsonrpc

build status

This is a node package to support in the implementation of a user authentication end-point.

The implementation of user-auth-jsonrpc is based on the following main packages:

  • express: to implement the http server
  • mongodb: to persiet the user information
  • node-jose: to generate the authorization tokens
  • nodemailer: to send confirmation emails to the user

In order to use this package your code/environment should meet the following:

  • Http routing based on express
  • Storage backend based on MongoDB
  • To provide options and credentials to communicate with a SMTP server
  • To provide the email template files with the content of the confirmation body sent to the users.

Installation

npm install user-auth-jsonrpc

Tests

npm run lint

npm test

Usage

const express = require('express');
const userAuth = require('./user-auth-jsonrpc');
const {MongoClient} = require('mongodb');
const path = require('path');

// create the express app object
const app = express();

// create the authentication router
let routerRpc = express.Router();
app.use('/', routerRpc);

function start() {
    return MongoClient.connect('mongodb://localhost:27017/user_auth')
        .then(db => {
            // mount the router on the path '/auth'
            return userAuth.mount(routerRpc, {
                path: '/auth',
                db: db,
                mail: {
                    sender: '[email protected]',
                    dirTemplates: path.join(__dirname, 'templates/mail'),
                    templates: ['confirm-register', 'confirm-password']
                }
            });
        })
        .then(_=>{
            app.listen(0, _=>{
                console.log('Server started');
            });
        });
};

start();

Email Configuration

The configuration is based on the package mailer-template.

In the example above we have used the following template structure:

├── templates
    └── mail
        ├── confirm-password.html.mst
        ├── confirm-password.json
        ├── confirm-register.html.mst
        └── confirm-register.json

With the following templates contents:

confirm-register.json


{
    "subject": "Activate your account in The_Marvellouse_Account",
    "images": []
}

confirm-register.html.mst


<p>Hi {{profile.name}},</p>
<p>Thanks for signing up for The_Marvellouse_Service!</p>
<p>Please confirm your account at <a class=activate href="{{href}}">activate</a></p>

confirm-password.json


{
    "subject": "Password change requested in The_Marvellouse_Account",
    "images": []
}

confirm-password.html.mst


<p>Hi, {{profile.name}}</p>
<p>You have recently requested to change the password in your account for The_Marvellouse_Service!</p>
<p>Please confirm the change at <a class=activate href="{{href}}">confirm change</a></p>

Template View

Each template is rendered using mustache and the view object which can be expanded in the templates has the following structure:

{
   profile: {...},
   href: '...'
}

where,

  • profile is the corresponding profile field from the user document in the database. You can use in the template, for instance, the name of the user like {{profile.name}}
  • href is the link to confirm the action (register or password change)

API

You can see the documentation of the client API for the implemented end-point at API doc

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.