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

moon-contrib-user

v0.0.4

Published

an authentication module for moonshine-js

Downloads

8

Readme

Moonshine user component

Moon-contrib-user is a User and Authentication Component for Moonshine using passport.js.

###Moon-contrib-user

  • Service:

  • user :

    • addStrategy: A function that allows adding a passport.js strategy (it's an alias for passport.use
    • authenticate: an alias for passport.authenticate
    • native : access the passport.js object directly
    • getUser(request): a function that given an express.js object return's the User object (useful for cases where the user object isn't named user)
  • Applicable settings:

  • SESSION_SECRET_TOKEN: the secret token used to encrypt Sessions

  • USER_REQUIRE_AUTH_BY_DEFAULT: if true all REST resources are only available to authenticated users unless specified directly. if false, only resources that are specified are blocked to none authenticated user. --defaults to true

  • USER_REQUEST_PROPERTY_NAME: the express.js request object proprty name that stores user info. --defaults to 'user'

  • COOKIE_SECRET_TOKEN: secret token to encrypt cookies.

  • Resource options:

  • requireAuth: determines if a resource is only visible to authenticated users. (see also settings:USER_REQUIRE_AUTH_BY_DEFAULT)

  • Entities: *user: a new, user entity has been added both as a model and a resource. *"/users/me" : this route allows viewing the authenticated user's resource. *"/users/logout": this route allows logging out for the authenticated user. This api takes no payload, and returns a 204 response.

  • Model extensions:

  • authorize: you can add a static method to a model called authorize. All get/post/put requests on a resource for that model will first authorize using that method.

    The method gets the following arguments:

    • user - the user object.
    • action - the type of action - "view","update" or "create"
    • object - the object in question (a json object in case of view or create, and the actual object in update)
    • change - a list of changes to be made (in case of update)

    The method should return a boolean value indicating if the user is authorized to perform this action.

  • applyLimit: you can add a static method to a model called applyLimit. If exists all REST requests to view a collection for the model will first go through that function to limit the returned object (usually done to limit a user to view only his own objects). The method gets the following arguments:

    • user - the user object.
    • query - the Baucis query object to apply the limit on.
  • Helper methods:

  • require("moon-contrib-user").authorizeByUserRef - a convienient factory method to create an authorize method that authorizes a user to act only on it's own object (assuming that object has a reference field called user).

  • Angular modules:

  • user.authentication['/js/user.authentication.js'] :

    • routing permission: user.authentication provides additional routing capabilities. If a route (or state if using ui.router) has a permission field then before a route change is made that function will be called with the user object to authenticate).

      If the user is not authenticated he will be redirected to the login route (and compliting the login will return him to the requested route).

      The permission function recieves two attributes:

      • loggedIn - boolean value whether the user is logged in.

      • authentication - the authentication service. (see below)

        The authentication service has two special functions while in permission check- redirectToNext() - that redirects back to the route specified (or default) and doOnUnauthorizedAccess() that redirects to login.

    • Constants:

      • authenticatedOnly- a convieniance permission function that limits routes only to users who are authenticated.
      • notForAuthenticated - a convieniance permission function that doesn't allow a route to be viewed by authenticated users.
    • Services :

      • authenticationProvider:
      • registerAuthenticator(name,authenticator): registers a new authenticator with the given name.
      • setDefaultAuthenticator(name/function): sets the authenticator as the default authenticator by name or reference.
      • authenticaton:
      • checkAuthenticated(force): checks if the user is authenticated. returns a promise for a boolean value.
      • authenticate(authenticatorName,authInfo): tries to authenticate the user with the given authenticator (authInfo is provided for authenticatorUse)
      • loginRoute: the default route for login (if a user tries to access an authenticated only route and is redirected). --defaults to '/login'
      • register(userInfo,callback): used to register a new user. automatically logs user in. userInfo must contain all info needed for user registration.
      • logout(callback): logs user out.
    • Controllers :

      • AuthLoginCtrl:
      • AuthRegisterCtrl:
      • AUTHLogoutCtrl: