moon-contrib-user
an authentication module for moonshine-js
Last updated 7 years ago by illniyar .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install moon-contrib-user 
SYNC missed versions from official npm registry.

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:

Current Tags

  • 0.0.4                                ...           latest (7 years ago)

4 Versions

  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |