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

imicros-auth

v0.0.14

Published

Moleculer services for Authentication, Authorization and ACL

Downloads

435

Readme

imicros-auth

Build Status Coverage Status

Moleculer services for Authentication

Installation

$ npm install imicros-auth --save

Dependencies

Requires a running Mongo Instance.

Requires a running service which can be called to handle

  • requestVerificationMail
  • requestPasswordReset

Usage

Usage Users

const { ServiceBroker } = require("moleculer");
const { Users } = require("imicros-auth");

broker = new ServiceBroker({
    logger: console
});
service = broker.createService(Users, Object.assign({ 
    settings: { 
        uri: mongoUri,
        requestVerificationMail: {
            call: "flow.publisher.emit",
            params: {
                topic: "users",
                event: "requestVerificationMail",
                payload: "params"
            }
        },
        requestPasswordReset: {
            call: "flow.publisher.emit",
            params: {
                topic: "users",
                event: "requestPasswordReset",
                payload: "params"
            }
        }
    } 
}));
broker.start();

Actions

action create { email, password, locale } => { user }
action requestConfirmationMail { email } => { sent }
action confirm { token } => { verified }
action requestPasswordResetMail { email } => { sent }
action resetPassword { token, password } => { result }
action login { email, password } => { user, token }
action resolveToken { token } => { user }
action me { } => { user }

Create

For REST call via API. Or as a direct call:

let param = {
    email: "[email protected]",  // valid email
    password: "my secret",      // min 8
    locale: "en"                // optional - 2 character
}
broker.call("users.create", param).then(user => {
    // user.id is filled
})

requestConfirmationMail

For REST call via API. Or as a direct call:

let param = {
    email: "[email protected]"   // registered email (user created)
}
broker.call("users.requestConfirmationMail", param).then(user => {
    // calls the method under settings with default parameters:
    //   {
    //      email: user.email,
    //      locale: user.locale,
    //      token:  token
    //   }
    // the token should be added to a link in the confirmation mail
    // in case of a successful call it returns
    //  {
    //      sent: "[email protected]"
    //  }
})

confirm

This method must be called by the method which handles the confirmation link in the confirmation mail.

let param = {
    token: token  // valid token (received as return value from requestConfirmationMail)
}
broker.call("users.confirm", param).then(user => {
    // in case of a successful call it returns
    //  {
    //      verified: "[email protected]"
    //  }
})

requestPasswordResetMail

For REST call via API. Or as a direct call:

let param = {
    email: "[email protected]"   // registered email (user created)
}
broker.call("users.requestPasswordResetMail", param).then(user => {
    // calls the method under settings with default parameters:
    //   {
    //      email: user.email,
    //      locale: user.locale,
    //      token:  token
    //   }
    // in case of a successful call it returns
    //  {
    //      sent: "[email protected]"
    //  }
})

resetPassword

For REST call via API. Or as a direct call:

let param = {
    token: token,               // valid token (received as return value from requestPasswordResetMail)
    password: "my new secret",  // new password, min 8
}
broker.call("users.resetPassword", param).then(user => {
    // in case of a successful call it returns
    //  {
    //      reset: user.id
    //  }
})

login

For REST call via API. Or as a direct call:

let param = {
    email: "[email protected]",  // registered email (user created)
    password: "my secret"       // min 8
}
broker.call("users.login", param).then(user => {
    // in case of a successful call it returns
    //  {
    //      token: generated token
    //      user: user object
    //  }
})

resolveToken

This method is for calling in moleculer-web method authorize.
If further imicros services like imicros-groups or imicros-acl will be used, the user must be added to ctx.meta - at least user.id and user.email.

let param = {
    token: token                // valid token (received as return value from login)
}
broker.call("users.resolveToken", param).then(user => {
    // in case of a successful call it returns
    //  {
    //      user: user object
    //  }
})

me

For REST call via API. Must be authorized by token - ctx.meta.user.id is then filled and the user is returned.

broker.call("users.me", param).then(user => {
    // in case of a successful call it returns
    //  {
    //      user: user object
    //  }
})