Small module that allows to use JWT authentication with ng-admin.
https://github.com/akagadovskiy/ng-admin-jwt-auth-demoapp 1) Include .js file to your index.html2) 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
2) make run - runs browserify build and watcher
- Create roles configuration in ng-admin module
- Integrate role-based system to ng-admin.jwt-auth