Skip to content

akagadovskiy/ng-admin-jwt-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ng-admin-jwt-auth

Small module that allows to use JWT authentication with ng-admin.

Demo

https://github.com/akagadovskiy/ng-admin-jwt-auth-demoapp

Usage example:

1) Include .js file to your index.html
2) Include module in your application
 var app = angular.module('myApp', ['ng-admin', 'ng-admin.jwt-auth']);
3) Set full url to your authorization point:
    app.config(['NgAdminConfigurationProvider', 'RestangularProvider', 'ngAdminJWTAuthConfiguratorProvider', 
      function (NgAdminConfigurationProvider, RestangularProvider, ngAdminJWTAuthConfigurator) {
        var nga = NgAdminConfigurationProvider;
		    ngAdminJWTAuthConfigurator.setJWTAuthURL('http://localhost:3001/login');
        ...

That's all, authorization configured!

API reference:

  • setJWTAuthURL(fullUrl)
    ngAdminJWTAuthConfigurator.setJWTAuthURL('http://localhost:3001/login');
    
  • setCustomLoginTemplate(templateUrl):
    ngAdminJWTAuthConfigurator.setCustomLoginTemplate('customLoginTemplate.html');
    
  • setCustomAuthHeader(obj) - configure custom headers. By defauls authorization header is 'Authorization' and field 'Basic' adds for token. Final template of default authorization header is - Authorization: Basic {{token}}. You need to modify token template and replace 'Basic' by 'Bearer'. Here is an example:

      </p>
    
    ngAdminJWTAuthConfigurator.setCustomAuthHeader({
    	name: 'Authorization',
    	template: 'Bearer {{token}}'
    });
    
    
  • ngAdminJWTAuthConfigurator.setLoginSuccessCallback(callback) - adds callback that fires on successfull authentication with preserving default authentication proccess. Note that it's just adds, not replaces behaviour
  • ngAdminJWTAuthConfigurator.setLoginErrorCallback(callback) - adds error callback

Contribution

1) make install
2) make run - runs browserify build and watcher

TODO:

  • Create roles configuration in ng-admin module
  • Integrate role-based system to ng-admin.jwt-auth

Change Log

### Added: 1) ngAdminJWTAuthConfigurator.setNonProtectedStates(['custom/route']) - you can set up routes that are allowed to use without authentication. Important: you can use only custom urls. If you want to use CRUD url of some entity like tags/show/5 it will not work.