How to read response headers in angularjs applicaiton on FIRST TIME load(NOT USING $http or $resource)?

23 views
Skip to first unread message

Kumar Gopal

unread,
Aug 23, 2017, 5:40:17 AM8/23/17
to Angular and AngularJS discussion

I have a angularjs application which is deployed on app server and we have a single sign on web server which on successful authentication redirects to our application with the username in the response headers.

I have to read the username from the response headers when the angularjs application loads and use it to show on my application.



What i have tried:

  1. Used as below in my app.js :

    angular .module('myApp', [ 'ngResource', 'ngRoute', 'cgBusy', 'ui.bootstrap', 'ui.grid', 'ui.grid.pagination', 'ui.grid.moveColumns', 'ui.grid.selection', 'ui.grid.exporter', 'ngMaterial', 'angular-dropdown-multiselect' ]) .run(["$rootScope", function ($rootScope){

        var checkIfAuthenticated = function (next) {
          console.log('Inside checkIfAuthenticated ---> ' + next);
          var matchedData = next.match( /[\?\&]username=([^\&]+)/);
          console.log('Inside checkIfAuthenticated matchedData ---> ' + matchedData);
    
                var proxyUserMatch = next.match( /[\?\&]username=([^\&]+)/);
          console.log('Inside checkIfAuthenticated proxyUserMatch ---> ' + proxyUserMatch)
    
        };
        var firstTimeRoute = $rootScope.$on("$locationChangeStart", function(event, next, current) {
    
            console.log( "route change (first time)->current=[" + current + "], next=[" + next + "]");
    
            checkIfAuthenticated( next);
    
            firstTimeRoute(); // opt out of the event
        });
    }]);

Kumar Gopal

unread,
Aug 23, 2017, 5:40:17 AM8/23/17
to Angular and AngularJS discussion
Reply all
Reply to author
Forward
0 new messages