Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Fixing a Broken Interceptor

Fixing a Broken Interceptor

Scheduled Pinned Locked Moved Web Development
securityhelpcsharpjavascriptjson
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjb110
    wrote on last edited by
    #1

    We're developing a Angular 1 site that talks to a .NET WebAPI2 api. We have an interceptor related to the authentication side, but we're having problems with it. We are using a loading bar Angular component, and that component is reporting that the interceptor is broken. But we're not sure where/why and worse where to start investigating. By simple code elimination, the _request method seems to be ok (or at least doesn't cause issues, it might still be bad code!) Its the _responseSuccess method that causes the problem.

    'use strict';
    app.factory('authInterceptorService', ['$injector', '$q', '$location', 'localStorageService', function ($injector, $q, $location, localStorageService)
    {

    var authInterceptorServiceFactory = {};
    
    function RequiresRefresh(responseURL)
    {
        if (responseURL.indexOf('getcutofftime') > -1)
            return false;
        if (responseURL.indexOf('resources') !== -1)
            return true;
        return false;
    }
    
    var \_request = function (config)
    {
        config.headers = config.headers || {};
    
        var authData = localStorageService.get('authorizationData');
        if (authData)
        {
            config.headers.Authorization = 'Bearer ' + authData.token;
        }
    
        return config || q$.when(config);
    };
    
    //should handle all error responses in here.
    //var \_responseError = function (rejection)
    //{
    //    console.log("Intercepted Rejection: " + rejection);
    
    //    return $q.reject(rejection);
        
    //};
    
    var \_responseSuccess = function (response)
    {
        var responseURL = response.config.url;
        if (responseURL !== null && typeof responseURL !== 'undefined')
        {
            //check to make sure it's actually an interaction with the resourcesAPI - these are the only times it should refresh the token.
            if (RequiresRefresh(responseURL))
            {
                //get a new token!
                var authData = localStorageService.get('authorizationData');
    
                var JSONdata = {
                    windowsFullName: authData.windowsFullName
                    , windowsUserName: authData.windowsUserName
                    , summitUserName: authData.summitUserName
                    , summitFullName: authData.summitFullName
                    , clientID: 'MatterhornAuthApp'
                };
    
                $injector.get("$http")
                    .post(serviceBase + 'usermanagement/account/ReissueToke
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups