ng-admin

How to use authorization API in ng-admin app?


I've been thinking to use multiple APIs in my ng-admin app. I also have an another authorization API running on the host which provide tokens for other API calls.

I would like to use all above APIs in my ng-admin app. Customizing the API Mapping of the ng-admin documentation describes below code to authorize APIs

myApp.config(['RestangularProvider', function(RestangularProvider) {
var login = 'admin',
    password = '53cr3t',
    token = window.btoa(login + ':' + password);
RestangularProvider.setDefaultHeaders({'Authorization': 'Basic ' + token}); }]);

However, where is the place to specify my authorization api url here? How to config auth API to provide tokens to all other APIs? On the other hand, what I have to do for refresh tokens?

Thanks


Solution

  • http://ng-admin-book.marmelab.com/doc/Custom-pages.html

    go through the documentation of ng-admin and see how to add custom pages in ng-admin. I have used authorisation api in my code as follows:

    if(localStorage.getItem('yourTokenKey') !== null && localStorage.getItem("yourTokenKey") != 'undefined')
            $urlRouterProvider.otherwise("/dashboard");
        else
            $urlRouterProvider.otherwise("/login");
    
    $stateProvider
        .state('login',{            
            url:'/login',
            templateUrl:'templates/login.html',
            controller:'loginController'
        })
        .state('stats', {
            parent: 'main',
            url: '/stats',
            templateUrl: 'templates/inventoryFormTemplate.html'         
        })
        .state('dashboard2', {
            parent: 'main',
            url: '/dashboard'           
        })
        .state('inventoryItem', {
            parent: 'main',
            url: '/inventoryItem'           
        })
        .state('requestInventoryItem', {
            parent: 'main',
            url: '/requestInventoryItem'            
        })
        .state('logout', {          
            url: '/logout',
            controller:'logoutController'           
        });