1.4.0 • Published 7 years ago

sanji-auth-ui v1.4.0

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

sanji-auth-ui

Sanji auth service is part of Sanji UI framework and also it is a angular module. It accounts for authenticate and authorize a user based on json web token.

NPM Package Quality Build Status Coverage Status Codacy Badge dependencies devdependencies semantic-release Commitizen friendly

Dependencies

Installation

Sanji auth service is based on es6 + webpack to development and embrace npm to install it.

npm install sanji-auth-ui --save

How to use

You need to include module first.

angular.module('webapp', ['sanji.auth'])

and then use auth and session as DI service. auth service accounts for identifying user and session accounts for keeping login success information.

class AppController {
  constructor($http, auth, session) {
    this.credentials = { username: '', passowrd: '' };
    this.login = (credentials) => {
      // Authenticate a user
      this.auth.login('/auth/local', credentials)
      .then((data) => {
        // Return token data
        return this.$http.get('/users/me');
      })
      .then((res) => {
        // Return authenticated user data and save in session service
        session.setUserData(res.data);
      });
    }
  }
}
AppController.$inject = ['$http', 'auth', 'session'];

Configuration

authProvider

You can define roles to acheive access control. Default includes admin, user and guest.

let app = angular.module('webapp', ['sanji.auth']);
app.config(authProvider => {
  authProvider.configure({
    roles: {
      admin: 'admin',
      guest: 'guest'
    }
  });
});

sessionProvider

You can define token http header. Default is Authorization.

let app = angular.module('webapp', ['sanji.auth']);
app.config(sessionProvider => {
  sessionProvider.configure({
    tokenHeader: 'define-your-own-token-http-header'
  });
});

You also can define token key. Default is token. The key name must match your server response data. For example: token

let app = angular.module('webapp', ['sanji.auth']);
app.config(sessionProvider => {
  sessionProvider.configure({
    tokenKey: 'token'
  });
});

By the way, you can save autheticated user data in session service,

let app = angular.module('webapp', ['sanji.auth']);
app.run(($http, session) => {
  $http.get('/users/me')
  .then(res => {
    session.setUserData(res.data);
  });
});

Contact

Author: Zack Yang © 2015

Support: if you find any problems with this library, open issue on Github

1.4.0

7 years ago

1.3.0

8 years ago

1.2.9

9 years ago

1.2.8

9 years ago

1.2.7

9 years ago

1.2.6

9 years ago

1.2.5

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago