Created
May 1, 2016 02:05
-
-
Save DaveDevTV/bbfc83ef83c8562653ca1a692b68c6ea to your computer and use it in GitHub Desktop.
How to Intercept HTTP requests from angular to include an authorization token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('TokenInterceptor', function($q, $cookies, $location, $rootScope, $injector) { | |
return { | |
request: function(config) { | |
config.headers = config.headers || {}; | |
if($cookies.get('token')) { | |
config.headers.authorization = $cookies.get('token'); | |
} | |
return config; | |
} | |
} | |
}); | |
app.config(function($httpProvider) { | |
$httpProvider.interceptors.push('TokenInterceptor'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment