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

ng-auth-middleware

v0.7.0

Published

Authorization library For AngularJS

Downloads

13

Readme

ngAuthMiddleware

Library to provide user authentication and access management, browser-based JavaScript client Angularjs applications.

npm

Getting started

To install ngAuthMiddleware use npm

npm install ng-auth-middleware --save

Dependencies

 - angular
 - angular-permission
 - angular-cookies
 - @uirouter/angularjs

Inject the ngAuthMiddleware in your module and $authProvider to config the module while configuring your angular-application.

var app = angular.module("myApp", ["ngAuthMiddleware"]);

app.config([
  "$authProvider",
  function($authProvider) {
    $authProvider.configure({
      tokenStorage : 'localStorage', // by default cookie

      withPermission: true, // by default set false
      rolePropertyName: "userRole", // property name of role which become from server

      permissionPropertyName: "userPermissions", // property name of permission which become from server.

      roles: [
        {
          action: "href", // href or state

          roleName: "default", // name of each role

          afterSignIn: "applicant", // login according to role

          afterLogOut: "authorization.login" // logout according to role
        }
      ]
    });
  }
]);

Sample

There is a full example in the sample Folder.

This is preface sample:

app.config

App.congif.$inject = ["$authProvider"];
function AppConfig(authProvider) {
  authProvider.configure({
      
    withPermission: true,
    permissionPropertyName: "userPermissions",

    rolePropertyName: "userRole",

    roles: [
      {
        action: "href",
        roleName: "default",
        afterSignIn: "https://www.npmjs.com/package/ng-auth-middleware",
        afterLogOut: "https://www.npmjs.com"
      },
      {
        action: "state",
        roleName: "admin",
        afterSignIn: "admin.panel.dashboard",
        afterLogOut: "authorization.login"
      },
      {
        action: "state",
        roleName: "multiRole",
        afterSignIn: "module.panel.selectedRole",
        afterLogOut: "authorization.login"
      }
    ]
  });
}

updateRole Method Sample

It takes a param where the new role name is assigned, this method remove all roles of user and replace new role which get from param. you can use this method when you have multirole and choose one of them and remove rest of it.

$auth.updateRole(roleName);

user Method Sample

return store data.

$auth.user();

signIn Method Sample

It stores the information coming from the server and directs the user to the target given the role and address entered in the configuration.

$auth.signIn(response);

notAuthorized Method Sample

Invokes the method afterSingIn() if the user does not have access to a page

$auth.notAuthorized();

isAuthenticated Method Sample

Returns a boolean whether or not the user is authenticated

$auth.isAuthenticated();

logOut Method Sample

First it clears all data and roles Given the role and address entered in Configuration, it redirects the user to that target.

auth.logOut();

Running the Sample

npm start and then browse to http://localhost:5000.

Docs

Some initial docs are here.

First step:

Inject ngAuthMiddleware in app module.

var app = angular.module("myApp", ["ngAuthMiddleware"]);

Second step:

Inject $authProvider in config file, as mentioned above the object exist in authProviderConfigure() has some properties which want explain here:

create object of authProvider.

authProvider.configure({
  withPermission: false,

  rolePropertyName: "userRole",

  roles: [
    {
      action: "state",

      roleName: "defult",

      afterSignIn: "app.dashboard",

      afterLogOut: "app.login"
    }
  ]
});

"with permission":

Could set false or true, if set false you haven't connection with angular-permission else you have connected with angular-permission, if you dont set value by default set false.

"permissionPropertyName":

The response you receive from the server in which property the permissions are assigned. if 'withPermission' is true, it will be requirement.

"rolePropertyName":

The response you receive from the server in which property the roles are assigned.

"roles":

This property is array which set objects,each object says how to behave with each role:

"roles > action":

Could set href or state, href uses for change url in one project externally, state uses for change url in one project internally.

"roles > roleName":

Could set name of role and you can set just one role, if your project has multiRole, you have to set multiRole for value of roleName and go to selected role page to choose one role, and at the end you have to set default for one of objects which exist in roles array.

"afterSignIn":

As is clear from the word, which page to go after login. for deactive this,set false.

"afterLogOut":

As is clear from the word, which page to go after logOut. for deactive this,set false.

Feedback, Feature requests, and Bugs

All are welcome on the issue tracker.